strip path option

This commit is contained in:
Connor Olding 2013-05-20 20:10:49 -07:00
parent 2ed08389c9
commit 2edb454851

35
lsf.sh
View file

@ -11,8 +11,6 @@
# for loops over "${array[@]}" as it works the same in both # for loops over "${array[@]}" as it works the same in both
# TODO: set better defaults for quick glances at filesize # 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 # TODO: include sorting somehow
_lsf_begin(){ _lsf_begin(){
@ -86,7 +84,6 @@ function trunc(str, len) {
function fixlen(str, len) { function fixlen(str, len) {
return trunc(sprintf("%" len "s", str), len) return trunc(sprintf("%" len "s", str), len)
} }
{ {
printff("size", $(NF-14)) printff("size", $(NF-14))
@ -95,11 +92,12 @@ function fixlen(str, len) {
is_me=(uid==me) is_me=(uid==me)
is_us=(gnames[gid] in us) is_us=(gnames[gid] in us)
gross=("0x" $(NF-12))+0 bits=("0x" $(NF-12))+0
type=rshift(gross, 9) # note: we ignore the set and sticky bits... for now
operm=and(gross, 07) type=rshift(and(bits, 0170000), 12)
gperm=rshift(and(gross, 070), 3) operm=and(bits, 07)
uperm=rshift(and(gross, 0700), 6) 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) our_perm=or(or((is_me)?uperm:0, (is_us)?gperm:0), operm)
printf(pc[our_perm] "%o " clr, our_perm) printf(pc[our_perm] "%o " clr, our_perm)
@ -111,13 +109,13 @@ function fixlen(str, len) {
if(OSU) { if(OSU) {
name=fixlen((uid in unames)?unames[uid]:uid, 6) 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) printf("%s ", name)
} }
if(OSG) { if(OSG) {
name=fixlen((gid in gnames)?gnames[gid]:gid, 6) 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) printf("%s ", name)
} }
@ -134,14 +132,21 @@ function fixlen(str, len) {
printff("time", now-dc) 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 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(){ lsf(){
local o_showallperm=1 o_showuser=1 o_showgroup=1 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 while getopts $opts'h' opt; do
case $opt in case $opt in
f) _lsf_cached=;; f) _lsf_cached=;;
@ -149,6 +154,7 @@ lsf(){
u) o_showuser=0;; u) o_showuser=0;;
g) o_showgroup=0;; g) o_showgroup=0;;
m) o_mostrecent=1;; m) o_mostrecent=1;;
s) o_showpath=0;;
?) echo "usage: $0 [-$opts] [dir]" ?) echo "usage: $0 [-$opts] [dir]"
return 1;; return 1;;
esac esac
@ -159,7 +165,8 @@ lsf(){
shift $((OPTIND-1)) shift $((OPTIND-1))
find "${1:-.}" -maxdepth 1 -exec stat -t {} + | awk --non-decimal-data \ find "${1:-.}" -maxdepth 1 -exec stat -t {} + | awk --non-decimal-data \
-v"now=$(date +%s)" -v"OMR=$o_mostrecent" -v"OSU=$o_showuser" \ -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 case $- in