Sort .gitmodules, also easily adaptable to sort files in blocks (e.g. 4 lines at a time, or arbitrary region at a time).
See also:
#!/usr/bin/env bash
awk 'BEGIN { I=0 ; J=0 ; K="" } ; /^\[submodule/{ N+=1 ; J=1 ; K=$2 ; gsub(/("vendor\/|["\]])/, "", K) } ; { print K, N, J, $0 } ; { J+=1 }' .gitmodules \
| sort \
| awk '{ $1="" ; $2="" ; $3="" ; print }' \
| sed 's/^ *//g' \
| awk '/^\[/{ print ; next } { print "\t", $0 }' \
> .gitmodules
Hey, just wanted to say I found this very useful, except for the fact that having that piped command immediately overwriting
> .gitmodules
deletes the contents of.gitmodules
before the command actually runs. See https://serverfault.com/questions/135507/linux-how-to-use-a-file-as-input-and-output-at-the-same-timeThe first time I ran it I basically nuked my
.gitmodules
folder. Might want to edit this so others don't do the same.