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:
parent
c53605031a
commit
ff6489bff5
2
sh/e
2
sh/e
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
4
sh/trunc
4
sh/trunc
|
@ -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 "$@"
|
||||
|
|
Loading…
Reference in New Issue
Block a user