Created
August 2, 2019 11:18
-
-
Save Zibri/894bfe7f37ed55e07a3773c14da8673c to your computer and use it in GitHub Desktop.
Reindent any bash script the "bash" way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# By Zibri (www.zibri.org) | |
# Usage: reindent script.sh >script_nicer.sh | |
# | |
reindent () | |
{ | |
rstr=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1); | |
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/ /" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment