I\'m looking for something similiar to indent but for (bash) scripts. Console only, no colorizing, etc.
Do you know of one ?
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 eliminates comments and reindents the script "bash way".
If you have HEREDOCS in your script, they got ruined by the 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 script will have a 4 spaces indentation.
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/ /"
}
which takes care also of heredocs.