3 ms·
A (cheap) trick for formatting shell scripts is approximately: wrap script into a shell function source function definition diff defined function against
by dmckeon 13y ago
A (cheap) trick for formatting shell scripts is approximately:
wrap script into a shell function
source function definition
diff defined function against script
with something like:
{ printf 'dummy (){ '
cat script
printf "; };\ntype -a dummy\n"
} > dummy
source dummy > defined
rm dummy; unset -f dummy
diff script defined
Issues include:
comments are absent from defined function listing
trailing semicolons appear after each shell command / line
the first semi in the trailing "; };" may be a syntax error
The default function listing format is fairly generic, so personal
formatting preferences must be left as an exercise for the reader.
MHO: people who insist on specific code formats should provide tools
that can convert arbitrary code into their preferred format.