#!/usr/bin/env zsh

lang=$1 ; shift
names=$1 ; shift

for source in $@; do
	perl -e 'print sort { length($b) <=> length($a) } <>' < $names |
		while read name; do
			clear
			git co -- $source
			msg="Tag instances of name '$name' as language '$lang'"
			perl -i -pne "s/(?<!\})$name(?!\})/\\\\lang$lang{$name}/g if ! /^(\[\^\d+\]|#+ )/" -- $source
			git add -- $source
			git --no-pager diff --cached -U0 --word-diff=color --minimal --ignore-all-space -- $source |
				grep -v '@@'
			git diff-index --quiet --cached HEAD && continue 1
			read -q "?$msg? (y/n)" || continue 1
			git commit -m "[auto] $msg"
		done
done

#!/usr/bin/env zsh

lang=$1 ; shift
names=$1 ; shift

for source in $@; do
	awk '{ print length, $0 }' < $names | sort -n | cut -d' ' -f2- |
		while read name; do
			clear
			git co -- $source
			msg="Tag instances of name '$name' as language '$lang'"
			perl -i -pne "s/(?<!\})$name(?!\})/\\\\lang$lang{$name}/g if ! /^(\[\^\d+\]|#+ )/" -- $source
			git add -- $source
			git --no-pager diff --cached -U0 --word-diff=color --minimal --ignore-all-space -- $source |
				grep -v '@@'
			git diff-index --quiet --cached HEAD && continue 1
			read -q "?$msg? (y/n)" || continue 1
			git commit -m "[auto] $msg"
		done
done

--- 
+++ 
@@ -4,7 +4,7 @@
 names=$1 ; shift
 
 for source in $@; do
-	perl -e 'print sort { length($b) <=> length($a) } <>' < $names |
+	awk '{ print length, $0 }' < $names | sort -n | cut -d' ' -f2- |
 		while read name; do
 			clear
 			git co -- $source
Simplify using Perl oneliner and _actually_ reverse the order
