From 2edb454851e1a8cf6284fc124052d0b25ae02a15 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Mon, 20 May 2013 20:10:49 -0700 Subject: [PATCH] strip path option --- lsf.sh | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lsf.sh b/lsf.sh index c1c8202..43e7e5a 100755 --- a/lsf.sh +++ b/lsf.sh @@ -11,8 +11,6 @@ # for loops over "${array[@]}" as it works the same in both # TODO: set better defaults for quick glances at filesize -# TODO: utilize filetype; opt to strip path from output -# make sure to add / to path if necessary (warning: symlinks) # TODO: include sorting somehow _lsf_begin(){ @@ -86,7 +84,6 @@ function trunc(str, len) { function fixlen(str, len) { return trunc(sprintf("%" len "s", str), len) } - { printff("size", $(NF-14)) @@ -95,11 +92,12 @@ function fixlen(str, len) { is_me=(uid==me) is_us=(gnames[gid] in us) - gross=("0x" $(NF-12))+0 - type=rshift(gross, 9) - operm=and(gross, 07) - gperm=rshift(and(gross, 070), 3) - uperm=rshift(and(gross, 0700), 6) + bits=("0x" $(NF-12))+0 + # note: we ignore the set and sticky bits... for now + type=rshift(and(bits, 0170000), 12) + operm=and(bits, 07) + gperm=rshift(and(bits, 070), 3) + uperm=rshift(and(bits, 0700), 6) our_perm=or(or((is_me)?uperm:0, (is_us)?gperm:0), operm) printf(pc[our_perm] "%o " clr, our_perm) @@ -111,13 +109,13 @@ function fixlen(str, len) { if(OSU) { name=fixlen((uid in unames)?unames[uid]:uid, 6) - if(is_me) name=YEL name clr + if(is_me) name=WHI name clr printf("%s ", name) } if(OSG) { name=fixlen((gid in gnames)?gnames[gid]:gid, 6) - if(is_us) name=YEL name clr + if(is_us) name=WHI name clr printf("%s ", name) } @@ -134,14 +132,21 @@ function fixlen(str, len) { printff("time", now-dc) } - # print filename by killing all fields not part of it + # acquire filename by killing all fields not part of it NF-=15 - print + fn=$0 + + if (!OSPA) { + if (NR!=1) fn=substr(fn,firstlen) + else firstlen=length(fn)+((type==04)?2:1) + } + + print fn }' lsf(){ local o_showallperm=1 o_showuser=1 o_showgroup=1 - local o_mostrecent=0 opts=mgupf opt + local o_mostrecent=0 o_showpath=1 opts=mgupfs opt while getopts $opts'h' opt; do case $opt in f) _lsf_cached=;; @@ -149,6 +154,7 @@ lsf(){ u) o_showuser=0;; g) o_showgroup=0;; m) o_mostrecent=1;; + s) o_showpath=0;; ?) echo "usage: $0 [-$opts] [dir]" return 1;; esac @@ -159,7 +165,8 @@ lsf(){ shift $((OPTIND-1)) 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" +-v"OSG=$o_showgroup" -v"OSP=$o_showallperm" -v"OSPA=$o_showpath" \ +"BEGIN{$_lsf_cached}$_lsf_program" } case $- in