The altshfmt is an experimental tool for formatting AltSH (alternative shell script) with extended syntax that cannot be formatted correctly by shfmt. This is implemented as a wrapper for shfmt.
Currently supported syntax: ShellSpec, shpec
- It has not been enough tested. Please make sure to save and version control your files properly so that they can be restored even if they are corrupted.
- It depends on the behavior of
shfmt, so it may not work depending on the combination of versions. - Incompatible changes may be made.
- shfmt v3.2.1
- Basic commands (
awk,cat,cmp,cp,diff,grep,ls,mktemp,rm,sed,which)
Since altshfmt is implemented as compatible as possible with shfmt, You can use it instead of the shfmt command.
- Download
altshfmtarchive from here and extract it to a directory, or usegit clone. - Download
shfmtbinary from here and save it in the directory wherealtshfmtis located.
WSL (Windows 10, version 1803 and later) or busybox-w32 is required. To run it from Windows (instead of from WSL), run altshfmt.bat instead of altshfmt.
- Download
altshfmtarchive from here and extract it to a directory, or usegit clone. - Download
shfmtbinary from here and save it in the directory wherealtshfmtis located. - The
shfmtbinary can be used for Windows or Linux.
- Download
altshfmtarchive from here and extract it to a directory, or usegit clone. - Download
shfmtbinary from here and save it in the directory wherealtshfmtis located. - Download
busyboxbinary from here, rename it tobash.exeand save it in the directory wherealtshfmtis located.
Use the shell-format (github) extension.
- Install the shell-format extension and change
shellformat.pathinsettings.jsonto the path to thealtshfmt(oraltshfmt.batfor windows).
The syntax is automatically determined from the beginning and ending pairs of the block of DSL used in the shell script.
If you have problems with the automatic detection, you can also use the shell directive. The shell directive is a comment that begins with "shell:".
Example
#!/bin/sh
# shell: sh altsh=shellspec
Describe
...
EndUsage: shell: [<shell>] [altsh=<syntax>]
shell:sh,bash,mksh- Unspecified: same as
auto - It is treated as the value of the
-lnflag of theshfmtcommandauto: do not specify the-lnflagsh: implies-ln posixbash: implies-ln bashmksh: implies-ln mksh- Others: implies
-ln bash
- Unspecified: same as
syntax:shellspec,shpec- Unspecified: Treat it as a pure shell script
- Others: Treat it as a pure shell script
altshfmt is several times slower than shfmt.