On Thu, 5 Mar 2009 09:51:16 +0100 Martin Klaiber <martinkl@xxxxxxxxxxxxxxxxxx> wrote: > Does someone know of an improved version of shmode.sl which supports > indentation? Or any other way to get indentation when writing shell > scripts for unix/linux (bourne-shell-like). > > TIA, Martin > Hi, A lot of time ago (circa 2002), I wrote an extended version of shmode.sl, just to add indentation support. While the indentation algorithm is far from perfect, is does a good job on most cases. I use it and I don't remember having big problems with it, but as I wrote it, maybe is targeted at my coding style... As there are some known cases that makes the indentation misbehave, I just added a "backdoor" to restore the correct indentation. So, for example: -------- echo "$BackupPatterns" | while read i ; do ls -a "$1" | grep "$i" 2> /dev/null \ | while read line ; do echo "$1/$line" done done # <-- Bad! Should be at 'echo "$BackupPatterns" | ...' level! IFS="$SaveIFS" # <-- and the error propagates. -------- the mis-indentation can be fixed adding a marker, as in: -------- echo "$BackupPatterns" | while read i ; do ls -a "$1" | grep "$i" 2> /dev/null \ | while read line ; do echo "$1/$line" done #!# -1 fix indentation done # now this is ok IFS="$SaveIFS" # <-- and so on -------- Note t marker '#!# -1 etc': this tells to the indentation algorithm to correct indentation adding a '-1' indentation level. Obviously you can use any number there. The marker can be configured defining the variable 'SH_INDENT_FIX_MARKER', and defaults to '#!#'. Hope this helps! Dino
Attachment:
shmode.sl
Description: Binary data
Attachment:
signature.asc
Description: PGP signature