mirror of
https://github.com/notwa/rc
synced 2024-07-01 03:07:13 -07:00
more lsz updates
This commit is contained in:
parent
6dd9dd07ba
commit
202aeb8588
62
sh/lsz
62
sh/lsz
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
# TODO: safe-ify echos and prints
|
|
||||||
local din=${1:-$(pwd)}
|
emulate -L zsh
|
||||||
din=${din%/} # TODO: hackish
|
setopt ksh_typeset typeset_silent
|
||||||
|
|
||||||
local -A unames gnames us
|
local -A unames gnames us
|
||||||
while IFS=: read -rA A; do unames[${A[3]}]=${A[1]} done < /etc/passwd
|
while IFS=: read -rA A; do unames[${A[3]}]=${A[1]} done < /etc/passwd
|
||||||
|
@ -10,7 +10,7 @@ for x in $(groups); do us[$x]=1 done
|
||||||
|
|
||||||
local -a colors
|
local -a colors
|
||||||
colors=(bla red gre yel blu pur cya whi)
|
colors=(bla red gre yel blu pur cya whi)
|
||||||
local i= $=colors ${(U)=colors} clr=$'\e[0m'
|
local i $=colors ${(U)=colors} clr=$'\e[0m'
|
||||||
for i in {0..7}; do
|
for i in {0..7}; do
|
||||||
local x=${colors[$((i+1))]}
|
local x=${colors[$((i+1))]}
|
||||||
eval "$x=$'\\e[3${i}m'" "${(U)x}=$'\\e[9${i}m'"
|
eval "$x=$'\\e[3${i}m'" "${(U)x}=$'\\e[9${i}m'"
|
||||||
|
@ -19,8 +19,6 @@ done
|
||||||
local s=1 m h d y B=1 K M G T
|
local s=1 m h d y B=1 K M G T
|
||||||
noglob let m=60*s h=60*m d=24*h y=365*d K=1024*B M=1024*K G=1024*M T=1024*G
|
noglob let m=60*s h=60*m d=24*h y=365*d K=1024*B M=1024*K G=1024*M T=1024*G
|
||||||
|
|
||||||
local -a ft fut fct fs fus fcs
|
|
||||||
|
|
||||||
local s_ft='
|
local s_ft='
|
||||||
y*10 y BLA
|
y*10 y BLA
|
||||||
y*2 y blu
|
y*2 y blu
|
||||||
|
@ -52,26 +50,18 @@ local permcolors="$BLA $WHI $yel $YEL $blu $BLU $gre $GRE"
|
||||||
permcolors=($=permcolors)
|
permcolors=($=permcolors)
|
||||||
|
|
||||||
# chr dir blk file sym
|
# chr dir blk file sym
|
||||||
local typecolors="$RED $BLA $BLA $BLA $BLU $BLA $BLA $BLA $clr $BLA $CYA"
|
local typecolors="$RED $BLA $YEL $BLA $BLU $BLA $yel $BLA $clr $BLA $CYA"
|
||||||
typecolors=($=typecolors)
|
typecolors=($=typecolors)
|
||||||
|
|
||||||
|
local ft fs
|
||||||
local min unit color
|
local min unit color
|
||||||
for min unit color in $=s_ft; do
|
for min unit color in $=s_ft; do
|
||||||
# TODO: consider dereferencing color
|
|
||||||
ft+=($(($min)) $unit $color)
|
ft+=($(($min)) $unit $color)
|
||||||
done
|
done
|
||||||
for min unit color in $=s_fs; do
|
for min unit color in $=s_fs; do
|
||||||
fs+=($(($min)) $unit $color)
|
fs+=($(($min)) $unit $color)
|
||||||
done
|
done
|
||||||
|
|
||||||
trunc() { # deprecate me for speed...
|
|
||||||
local len=${1:-$COLUMNS} c='…' L
|
|
||||||
local end=$((len-1))
|
|
||||||
while read -r L; do
|
|
||||||
[ ${#L} -gt $len ] && echo ${L[1,$end]}$c || echo $L
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
prettify() {
|
prettify() {
|
||||||
local min unit color
|
local min unit color
|
||||||
for min unit color in ${(P)2}; do
|
for min unit color in ${(P)2}; do
|
||||||
|
@ -99,7 +89,7 @@ permprint() {
|
||||||
}
|
}
|
||||||
|
|
||||||
typeprint() {
|
typeprint() {
|
||||||
echo -n ${typecolors[$(($1+1))]} #${(l:3:)1}
|
echo -n ${typecolors[$(($1+1))]}
|
||||||
}
|
}
|
||||||
|
|
||||||
local now=$(date +%s)
|
local now=$(date +%s)
|
||||||
|
@ -107,18 +97,40 @@ dateprint() {
|
||||||
[ $1 -lt 32 ] \
|
[ $1 -lt 32 ] \
|
||||||
&& echo -n "$BLA N/A$clr" \
|
&& echo -n "$BLA N/A$clr" \
|
||||||
|| prettify $((now-$1)) ft
|
|| prettify $((now-$1)) ft
|
||||||
|
echo -n ' '
|
||||||
}
|
}
|
||||||
|
|
||||||
local dinf=$(readlink -f $din/)
|
_lsz() {
|
||||||
local f="$dinf/*(D)"
|
local din=${1:-$(pwd)}
|
||||||
|
din=${din%/}
|
||||||
|
|
||||||
|
local dinf=$(readlink -f ${din:-/})
|
||||||
|
local glob=$dinf
|
||||||
|
[ -d "$dinf" ] && glob=$dinf/*(DN)
|
||||||
|
|
||||||
|
local count=$2
|
||||||
|
[ $count -gt 1 ] && echo "$WHI$dinf"
|
||||||
|
|
||||||
|
local -a matches
|
||||||
|
matches=(${~glob})
|
||||||
|
[ ${#matches} -eq 0 ] && return
|
||||||
|
|
||||||
|
stat -t -- ${matches[@]} | while read -r; do
|
||||||
|
__lsz "$REPLY" "$dinf"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
__lsz() {
|
||||||
|
local A dinf=$2
|
||||||
|
read -rA A <<<$1
|
||||||
|
|
||||||
stat -t -- ${~f} | while read -rA A; do
|
|
||||||
local uid=${A[-12]} gid=${A[-11]} is_me=0 is_us=0
|
local uid=${A[-12]} gid=${A[-11]} is_me=0 is_us=0
|
||||||
local uname=${unames[$uid]} gname=${gnames[$gid]}
|
local uname=${unames[$uid]} gname=${gnames[$gid]}
|
||||||
[ $uid -eq $UID ] && is_me=1
|
[ $uid -eq $UID ] && is_me=1
|
||||||
[ -n "$gname" ] && [[ ${us[$gname]} -eq 1 ]] && is_us=1
|
[ -n "$gname" ] && [[ ${us[$gname]} -eq 1 ]] && is_us=1
|
||||||
|
|
||||||
local bits=$((16#${A[-13]})) type= uperm= gperm= operm= our_perm=
|
local bits type uperm gperm operm our_perm
|
||||||
|
bits=$((16#${A[-13]}))
|
||||||
let 'type=(bits & 8#170000) >> 12'
|
let 'type=(bits & 8#170000) >> 12'
|
||||||
let 'uperm=(bits & 8#700) >> 6'
|
let 'uperm=(bits & 8#700) >> 6'
|
||||||
let 'gperm=(bits & 8#70) >> 3'
|
let 'gperm=(bits & 8#70) >> 3'
|
||||||
|
@ -133,7 +145,10 @@ stat -t -- ${~f} | while read -rA A; do
|
||||||
*) prettify ${A[-15]} fs ;;
|
*) prettify ${A[-15]} fs ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
true && {
|
||||||
|
echo -n ' '
|
||||||
permprint $our_perm
|
permprint $our_perm
|
||||||
|
}
|
||||||
|
|
||||||
true && {
|
true && {
|
||||||
echo -n ' '
|
echo -n ' '
|
||||||
|
@ -157,4 +172,7 @@ stat -t -- ${~f} | while read -rA A; do
|
||||||
n=${n##$dinf/}
|
n=${n##$dinf/}
|
||||||
typeprint $type
|
typeprint $type
|
||||||
echo $n$clr
|
echo $n$clr
|
||||||
done
|
}
|
||||||
|
|
||||||
|
local f
|
||||||
|
for f; _lsz $f ${#@}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user