1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 08:29:02 -08:00
rc/sh/similar
Connor Olding d5f3f14d72 merge compatibility lines
RIP meaningful last-modified dates
2024-03-26 15:08:14 -07:00

19 lines
563 B
Bash
Executable file

#!/usr/bin/env sh
# YES_ZSH YES_BASH YES_DASH YES_ASH YES_BB_AWK
similar() { ### @-
### highlight adjacent lines up to the first inequivalent character.
[ $# -eq 0 ] || { printf "%s\n" "$0: does not take arguments" >&2; return 1; }
awk '
{
i=0
for(c=1;c<length;c++)
if(substr($0,c,1)==substr(L,c,1)) 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 "$@"