1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-06-25 16:57:12 -07:00

improve busybox awk compatibility

This commit is contained in:
Connor Olding 2021-10-01 12:00:23 -07:00
parent c53605031a
commit ff6489bff5
3 changed files with 7 additions and 7 deletions

2
sh/e
View File

@ -4,6 +4,8 @@
# NO_DASH
# NO_ASH
# works with busybox awk.
e() { ### @-
### wrap around `$EDITOR` to run it as root if necessary.
### this still needs some work to detect root-owned directories.

View File

@ -4,7 +4,7 @@
# YES_DASH
# YES_ASH
# does not work with busybox awk (yet?)
# works with busybox awk.
similar() { ### @-
### highlight adjacent lines up to the first inequivalent character.
@ -12,10 +12,8 @@ similar() { ### @-
awk '
{
i=0
split($0,a,"")
split(L,b,"")
for (c in a)
if (a[c]==b[c]) i++
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)

View File

@ -4,7 +4,7 @@
# YES_DASH
# YES_ASH
# does not work with busybox awk (yet?)
# works with busybox awk.
trunc() { ### @-
### truncate text to fit within your terminal using the unicode character `…`.
@ -18,7 +18,7 @@ trunc() { ### @-
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
COLUMNS=${COLUMNS:-$(tput cols)}
awk -vL=${1:-$COLUMNS} '{e=length>L?"…":"";print substr($0,0,L-(e?1:0)) e}'
awk -vL=${1:-$COLUMNS} '{e=length()>L?"…":"";print substr($0,0,L-(e?1:0)) e}'
}
[ -n "${preload+-}" ] || trunc "$@"