All Projects → mvdan → Sh

mvdan / Sh

Licence: bsd-3-clause
A shell parser, formatter, and interpreter with bash support; includes shfmt

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Sh

Sublime-Pretty-Shell
🐚 Shell Script Formatter / Syntax Checker (Powered by shfmt)
Stars: ✭ 28 (-99.36%)
Mutual labels:  formatter, beautify, shfmt
Atom Beautify
📣 Help Wanted - Looking for Maintainer: https://github.com/Glavin001/atom-beautify/issues/2572 | 💄 Universal beautification package for Atom editor (⚠️ Currently migrating to https://github.com/Unibeautify/ and have very limited bandwidth for Atom-Beautify Issues. Thank you for your patience and understanding ❤️ )
Stars: ✭ 1,501 (-65.44%)
Mutual labels:  beautify, formatter
Unibeautify
One Beautifier to rule them all, One Beautifier to clean them, One Beautifier to bring them all and in the darkness sheen them
Stars: ✭ 466 (-89.27%)
Mutual labels:  beautify, formatter
Pp sql
Rails ActiveRecord SQL queries log beautifier
Stars: ✭ 223 (-94.87%)
Mutual labels:  beautify, formatter
Godot Gdscript Toolkit
Independent set of GDScript tools - parser, linter and formatter
Stars: ✭ 214 (-95.07%)
Mutual labels:  parser, formatter
Tabloid
A minimal programming language inspired by clickbait headlines
Stars: ✭ 235 (-94.59%)
Mutual labels:  parser, interpreter
Uncrustify
Code beautifier
Stars: ✭ 2,442 (-43.77%)
Mutual labels:  beautify, formatter
Cub
The Cub Programming Language
Stars: ✭ 198 (-95.44%)
Mutual labels:  parser, interpreter
pre-commit-hooks
Standardizing our code quality tooling 🛠️
Stars: ✭ 44 (-98.99%)
Mutual labels:  formatter, shfmt
atom-perfectionist
Beautify CSS and SCSS
Stars: ✭ 19 (-99.56%)
Mutual labels:  formatter, beautify
Logo
A Logo interpreter written in Swift
Stars: ✭ 207 (-95.23%)
Mutual labels:  parser, interpreter
Craftinginterpreters
Repository for the book "Crafting Interpreters"
Stars: ✭ 4,298 (-1.04%)
Mutual labels:  parser, interpreter
Graphql Parser
A graphql query language and schema definition language parser and formatter for rust
Stars: ✭ 203 (-95.33%)
Mutual labels:  parser, formatter
Latexindent.pl
Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
Stars: ✭ 415 (-90.44%)
Mutual labels:  beautify, formatter
Php Textile
Textile markup language parser for PHP
Stars: ✭ 200 (-95.39%)
Mutual labels:  parser, formatter
Vim Autoformat
Provide easy code formatting in Vim by integrating existing code formatters.
Stars: ✭ 2,000 (-53.95%)
Mutual labels:  beautify, formatter
Command Line Api
Command line parsing, invocation, and rendering of terminal output.
Stars: ✭ 2,418 (-44.32%)
Mutual labels:  parser, posix
Monkey Rust
An interpreter for the Monkey programming language written in Rust
Stars: ✭ 174 (-95.99%)
Mutual labels:  parser, interpreter
Mbeautifier
MBeautifier is a MATLAB source code formatter, beautifier. It can be used directly in the MATLAB Editor and it is configurable.
Stars: ✭ 248 (-94.29%)
Mutual labels:  beautify, formatter
pretty-remarkable
Plugin for prettifying markdown with https://github.com/jonschlinkert/remarkable using custom renderer rules.
Stars: ✭ 22 (-99.49%)
Mutual labels:  formatter, beautify

sh

Go Reference

A shell parser, formatter, and interpreter. Supports POSIX Shell, Bash, and mksh. Requires Go 1.16 or later.

Quick start

To parse shell scripts, inspect them, and print them out, see the syntax examples.

For high-level operations like performing shell expansions on strings, see the shell examples.

shfmt

go install mvdan.cc/sh/v3/cmd/shfmt@latest

shfmt formats shell programs. See canonical.sh for a quick look at its default style. For example:

shfmt -l -w script.sh

For more information, see its manpage, which can be viewed directly as Markdown or rendered with scdoc.

Packages are available on Alpine, Arch, Docker, FreeBSD, Homebrew, MacPorts, NixOS, Scoop, Snapcraft, Void and webi.

gosh

go install mvdan.cc/sh/v3/cmd/gosh@latest

Proof of concept shell that uses interp. Note that it's not meant to replace a POSIX shell at the moment, and its options are intentionally minimalistic.

Fuzzing

We use Go's native fuzzing support, which requires Go 1.18 or later. For instance:

cd syntax
go test -run=- -fuzz=ParsePrint

Caveats

  • When indexing Bash associative arrays, always use quotes. The static parser will otherwise have to assume that the index is an arithmetic expression.
$ echo '${array[spaced string]}' | shfmt
1:16: not a valid arithmetic operator: string
$ echo '${array[dash-string]}' | shfmt
${array[dash - string]}
  • $(( and (( ambiguity is not supported. Backtracking would complicate the parser and make streaming support via io.Reader impossible. The POSIX spec recommends to space the operands if $( ( is meant.
$ echo '$((foo); (bar))' | shfmt
1:1: reached ) without matching $(( with ))
  • Some builtins like export and let are parsed as keywords. This allows statically building their syntax tree, as opposed to keeping the arguments as a slice of words. It is also required to support declare foo=(bar). Note that this means expansions like declare {a,b}=c are not supported.

JavaScript

A subset of the Go packages are available as an npm package called mvdan-sh. See the _js directory for more information.

Docker

To build a Docker image, checkout a specific version of the repository and run:

docker build -t my:tag -f cmd/shfmt/Dockerfile .

This creates an image that only includes shfmt. Alternatively, if you want an image that includes alpine, add --target alpine. To use the Docker image, run:

docker run --rm -v $PWD:/mnt -w /mnt my:tag <shfmt arguments>

Related projects

The following editor integrations wrap shfmt:

Other noteworthy integrations include:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].