Created
March 24, 2016 21:51
-
-
Save n-st/cf01e0f92d4ec09c751a to your computer and use it in GitHub Desktop.
Sort the sections of a Git config file (and the contents of the sections) alphabetically
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
awk '{ if ($1 ~ /^\[/) { section=$0; print $0 } else { printf section; print $0 } }' gitconfig | sort -t ']' -k1,1 | sed 's/\[.\+\]\([^\s]\+\)/\1/' > gitconfig.new | |
mv gitconfig.new gitconfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! 🚀
But it fails for keys containing brackets.
Something like this avoids that