In Bash, I do this:
reindent() { source <(echo "Zibri () {";cat "$1"; echo "}") declare -f Zibri|head --lines=-1|tail --lines=+3 | sed -e "s/^\s\s\s\s//" }
this excludes comments and repeats the text of the bash way script.
If your script has HEREDOCS, they were destroyed by sed in the previous function.
So use:
reindent() { source <(echo "Zibri () {";cat "$1"; echo "}") declare -f Zibri|head --lines=-1|tail --lines=+3" }
But all your scripts will be indented with 4 spaces.
Or you can do:
reindent () { rstr=$(mktemp -u "XXXXXXXXXX"); source <(echo "Zibri () {";cat "$1"|sed -e "s/^\s\s\s\s/$rstr/"; echo "}"); echo '#!/bin/bash'; declare -f Zibri | head --lines=-1 | tail --lines=+3 | sed -e "s/^\s\s\s\s//;s/$rstr/ /" }
who also takes care of the heirs.
Zibri
source share