pimp the hexdump function 'hd' for when there is none
This commit is contained in:
parent
ff42a866e9
commit
54a698d564
45
dot.mkshrc
45
dot.mkshrc
@ -1,5 +1,5 @@
|
||||
# $Id$
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.80 2013/04/27 18:19:44 tg Exp $
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.81 2013/05/02 21:46:29 tg Exp $
|
||||
#-
|
||||
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
|
||||
# 2011, 2012, 2013
|
||||
@ -54,10 +54,43 @@ alias doch='fc -ln -1 | sudo mksh -s'
|
||||
whence -p rot13 >/dev/null || alias rot13='tr \
|
||||
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \
|
||||
nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'
|
||||
whence -p hd >/dev/null || function hd {
|
||||
hexdump -e '"%08.8_ax " 8/1 "%02X " " - " 8/1 "%02X "' \
|
||||
-e '" |" "%_p"' -e '"|\n"' "$@"
|
||||
}
|
||||
if whence -p hd >/dev/null; then :; elif whence -p hexdump >/dev/null; then
|
||||
function hd {
|
||||
hexdump -e '"%08.8_ax " 8/1 "%02X " " - " 8/1 "%02X "' \
|
||||
-e '" |" "%_p"' -e '"|\n"' "$@"
|
||||
}
|
||||
else
|
||||
function hd {
|
||||
local -Uui16 -Z11 pos=0
|
||||
local -Uui16 -Z5 hv=2147483647
|
||||
local dasc line i
|
||||
|
||||
cat "$@" | if read -arN -1 line; then
|
||||
typeset -i1 line
|
||||
i=0
|
||||
while (( i < ${#line[*]} )); do
|
||||
hv=${line[i++]}
|
||||
if (( (pos & 15) == 0 )); then
|
||||
(( pos )) && print -r -- "$dasc|"
|
||||
print -n "${pos#16#} "
|
||||
dasc=' |'
|
||||
fi
|
||||
print -n "${hv#16#} "
|
||||
if (( (hv < 32) || (hv > 126) )); then
|
||||
dasc+=.
|
||||
else
|
||||
dasc+=${line[i-1]#1#}
|
||||
fi
|
||||
(( (pos++ & 15) == 7 )) && print -n -- '- '
|
||||
done
|
||||
while (( pos & 15 )); do
|
||||
print -n ' '
|
||||
(( (pos++ & 15) == 7 )) && print -n -- '- '
|
||||
done
|
||||
(( hv == 2147483647 )) || print -r -- "$dasc|"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
# Berkeley C shell compatible dirs, popd, and pushd functions
|
||||
# Z shell compatible chpwd() hook, used to update DIRSTACK[0]
|
||||
@ -229,7 +262,7 @@ function Lb64decode {
|
||||
[[ -o utf8-mode ]]; local u=$?
|
||||
set +U
|
||||
local c s="$*" t=
|
||||
[[ -n $s ]] || { s=$(cat;print x); s=${s%x}; }
|
||||
[[ -n $s ]] || { s=$(cat; print x); s=${s%x}; }
|
||||
local -i i=0 j=0 n=${#s} p=0 v x
|
||||
local -i16 o
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user