#!/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

function tag_name () {
	md=$1 ; shift
	name=$@
	clear
	git co -- $md
	msg="Tag instances of name '$name' as language '$lang'"
	perl -i -pne "s/(?<!\})$name(?!\})/\\\\lang$lang{$name}/g if ! /^(\[\^\d+\]|#+ )/" -- $md
	git add -- $md
	git --no-pager diff --cached -U0 --word-diff=color --word-diff-regex=. --minimal --ignore-all-space -- $md |
		grep -v '@@'
	git diff-index --quiet --cached HEAD && continue 1
	read -q "?$msg? (y/n)" || continue 1
	git commit -m "[auto] $msg"
}

for file in $@; do
	perl -e 'print sort { length($b) <=> length($a) } <>' < $names |
		while read name; do
			tag_name $file $name
		done
done

Refactor as function and show diffs by character
Refactor as function and show diffs by character
