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
altshfmt
archive from here and extract it to a directory, or usegit clone
. - Download
shfmt
binary from here and save it in the directory wherealtshfmt
is 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
altshfmt
archive from here and extract it to a directory, or usegit clone
. - Download
shfmt
binary from here and save it in the directory wherealtshfmt
is located. - The
shfmt
binary can be used for Windows or Linux.
- Download
altshfmt
archive from here and extract it to a directory, or usegit clone
. - Download
shfmt
binary from here and save it in the directory wherealtshfmt
is located. - Download
busybox
binary from here, rename it tobash.exe
and save it in the directory wherealtshfmt
is located.
Use the shell-format (github) extension.
- Install the shell-format extension and change
shellformat.path
insettings.json
to the path to thealtshfmt
(oraltshfmt.bat
for 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
...
End
Usage: shell: [<shell>] [altsh=<syntax>]
shell
:sh
,bash
,mksh
- Unspecified: same as
auto
- It is treated as the value of the
-ln
flag of theshfmt
commandauto
: do not specify the-ln
flagsh
: implies-ln posix
bash
: implies-ln bash
mksh
: 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
.