1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 05:59:04 -08:00
rc/sh/similar

27 lines
617 B
Text
Raw Normal View History

#!/usr/bin/env sh
2021-07-29 00:37:35 -07:00
# YES_ZSH
# YES_BASH
# YES_DASH
2021-09-23 06:48:05 -07:00
# YES_ASH
# does not work with busybox awk (yet?)
2021-07-29 00:37:35 -07:00
similar() { ### @-
2021-08-01 09:27:25 -07:00
### highlight adjacent lines up to the first inequivalent character.
[ $# -eq 0 ] || { printf "%s\n" "$0: does not take arguments" >&2; return 1; }
2021-07-29 00:37:35 -07:00
awk '
{
i=0
split($0,a,"")
split(L,b,"")
for (c in a)
if (a[c]==b[c]) i++
else break
#print substr($0,1,i) "\033[7m" substr($0,i+1) "\033[0m"
print "\033[31m" substr($0,1,i) "\033[0m" substr($0,i+1)
L=$0
}'
}
[ -n "${preload+-}" ] || similar "$@"