This commit is contained in:
Connor Olding 2013-05-20 16:58:54 -07:00
parent 31ebe0b649
commit 5865c56fd8

60
lsf.sh
View file

@ -67,26 +67,7 @@ i=0;for x in "${pc[@]}"; do echo "pc[$i]=$x"; let i++;done
}
_lsf_cached=
lsf(){
local o_showallperm=1 o_showuser=1 o_showgroup=1
local o_mostrecent=0 opts=mgupf opt
while getopts $opts'h' opt; do
case $opt in
f) _lsf_cached=;;
p) o_showallperm=0;;
u) o_showuser=0;;
g) o_showgroup=0;;
m) o_mostrecent=1;;
?) echo "usage: $0 [-$opts] [dir]"
return 1;;
esac
done
[ "$_lsf_cached" ] || _lsf_cached="$(_lsf_begin)"
local program='BEGIN{'"$_lsf_cached"'
now='"$(date +%s)"'
}
_lsf_program='
function printff(id, n) {
len=f[id "s"]
for(i=0;i<=len;i++) {
@ -122,19 +103,19 @@ function fixlen(str, len) {
our_perm=or(or((is_me)?uperm:0, (is_us)?gperm:0), operm)
printf(pc[our_perm] "%o " clr, our_perm)
if('$o_showallperm') {
if(OSP) {
printf(pc[uperm] "%o" clr, uperm)
printf(pc[gperm] "%o" clr, gperm)
printf(pc[operm] "%o " clr, operm)
}
if('$o_showuser') {
if(OSU) {
name=fixlen((uid in unames)?unames[uid]:uid, 6)
if(is_me) name=YEL name clr
printf("%s ", name)
}
if('$o_showgroup') {
if(OSG) {
name=fixlen((gid in gnames)?gnames[gid]:gid, 6)
if(is_us) name=YEL name clr
printf("%s ", name)
@ -143,14 +124,14 @@ function fixlen(str, len) {
da=$(NF-4)
dc=$(NF-3)
dm=$(NF-2)
if(!'$o_mostrecent') {
printff("time", now-da)
printff("time", now-dm)
printff("time", now-dc)
} else {
if(OMR) {
max=(da>dm)?da:dm
max=(max>dc)?max:dc
printff("time", now-max)
} else {
printff("time", now-da)
printff("time", now-dm)
printff("time", now-dc)
}
# print filename by killing all fields not part of it
@ -158,12 +139,31 @@ function fixlen(str, len) {
print
}'
lsf(){
local o_showallperm=1 o_showuser=1 o_showgroup=1
local o_mostrecent=0 opts=mgupf opt
while getopts $opts'h' opt; do
case $opt in
f) _lsf_cached=;;
p) o_showallperm=0;;
u) o_showuser=0;;
g) o_showgroup=0;;
m) o_mostrecent=1;;
?) echo "usage: $0 [-$opts] [dir]"
return 1;;
esac
done
[ "$_lsf_cached" ] || _lsf_cached="$(_lsf_begin)"
shift $((OPTIND-1))
find "${1:-.}" -maxdepth 1 -exec stat -t {} + | awk --non-decimal-data "$program"
find "${1:-.}" -maxdepth 1 -exec stat -t {} + | awk --non-decimal-data \
-v"now=$(date +%s)" -v"OMR=$o_mostrecent" -v"OSU=$o_showuser" \
-v"OSG=$o_showgroup" -v"OSP=$o_showallperm" "BEGIN{$_lsf_cached}$_lsf_program"
}
case $- in
*i*) ;;
*) lsf -f
*) lsf -f /var/lib
esac