trunc len

This commit is contained in:
Connor Olding 2013-05-14 19:07:50 -07:00
parent 85da14dad0
commit 6e286aec91

12
lsf.sh Normal file → Executable file
View file

@ -14,6 +14,7 @@
# TODO: utilize filetype; opt to strip path from output # TODO: utilize filetype; opt to strip path from output
# make sure to add / to path if necessary (warning: symlinks) # make sure to add / to path if necessary (warning: symlinks)
# TODO: rewrite trunc to use len # TODO: rewrite trunc to use len
# TODO: include sorting somehow
_lsf_begin(){ _lsf_begin(){
local begin=' local begin='
@ -99,8 +100,11 @@ function printff(id, n) {
} }
function trunc(str, len) { function trunc(str, len) {
# for the moment len doesnt do anything e=length(str)>len?"…":""
return gensub(/(.{5})..+/,"\\1…",1,sprintf("%6s",str)) 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') { 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 if(is_me) name=YEL name clr
printf("%s ", name) printf("%s ", name)
} }
if('$o_showgroup') { 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 if(is_us) name=YEL name clr
printf("%s ", name) printf("%s ", name)
} }