Commit: a628537e96fa3224ad0bb7056116d24cd3ee4de7
Parent: eac1628b05418476fa57b193a0c958e0e08fc34f
Author: Randy Palamar
Date: Fri, 29 Sep 2023 06:58:53 -0600
simplify bin/git-sortmodules
I still think this could be written entirely in awk but apparently
sort is a gawk feature.
Diffstat:
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/bin/git-sortmodules b/bin/git-sortmodules
@@ -1,12 +1,9 @@
#!/bin/sh
-awk 'BEGIN { I=0 ; J=0 ; K="" }
- /^\[submodule/{ N+=1 ; J=1 ; K=$2 ; gsub(/("vendor\/|["\]])/, "", K) }
- { print K, N, J, $0 } ; { J+=1 }' \
+awk '/^\[submodule/ { count++; smods[count] = $0; next }
+ /^\t/ { smods[count] = smods[count] $0 }
+ END { for (line in smods) print smods[line] }' \
.gitmodules \
| sort \
- | awk '{ $1="" ; $2="" ; $3="" ; print }' \
- | sed 's/^ *//g' \
- | awk '/^\[/{ print ; next } { print "\t" $0 }' \
- > .gitmodules.new && mv .gitmodules.new .gitmodules
-
+ | awk '{ gsub("\t", "\n\t"); print }' \
+ > .gitmodules.new && mv .gitmodules.new .gitmodules