diff --git a/lsf.sh b/lsf.sh old mode 100644 new mode 100755 index affcd38..a39be64 --- a/lsf.sh +++ b/lsf.sh @@ -14,6 +14,7 @@ # TODO: utilize filetype; opt to strip path from output # make sure to add / to path if necessary (warning: symlinks) # TODO: rewrite trunc to use len +# TODO: include sorting somehow _lsf_begin(){ local begin=' @@ -99,8 +100,11 @@ function printff(id, n) { } function trunc(str, len) { - # for the moment len doesnt do anything - return gensub(/(.{5})..+/,"\\1…",1,sprintf("%6s",str)) + e=length(str)>len?"…":"" + return substr(str,0,len-(e?1:0)) e +} +function fixlen(str, len) { + return trunc(sprintf("%" len "s", str), len) } { @@ -126,13 +130,13 @@ function trunc(str, len) { } if('$o_showuser') { - name=trunc((uid in unames)?unames[uid]:uid, 6) + name=fixlen((uid in unames)?unames[uid]:uid, 6) if(is_me) name=YEL name clr printf("%s ", name) } if('$o_showgroup') { - name=trunc((gid in gnames)?gnames[gid]:gid, 6) + name=fixlen((gid in gnames)?gnames[gid]:gid, 6) if(is_us) name=YEL name clr printf("%s ", name) }