Skip to content

Instantly share code, notes, and snippets.

@Zibri
Created August 2, 2019 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zibri/894bfe7f37ed55e07a3773c14da8673c to your computer and use it in GitHub Desktop.
Save Zibri/894bfe7f37ed55e07a3773c14da8673c to your computer and use it in GitHub Desktop.
Reindent any bash script the "bash" way.
#!/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