Retitlting
I don't know how wise it is to use an overelaborate precmd() but it is extremely useful for screen window titling.
Mine has now grown slightly beyond the realms of simple paramater expansion (ZshHardStatus):
if [[ $GID == 0 ]]; then
local trunc_chrs=15
else
local trunc_chrs=18
fi
local trunc="$((${trunc_chrs}-${#1}))"
local args="${${2:+${${${@[${#${@}}]##/*/}/#/ }:-}}//\"/}"
if [[ ${#args} -ge $trunc ]]; then
local args="${(r:$trunc:::::):-${args}}.."
fi
print -nRP $'\033k%(!.#\[.)'${1}${args}\
$'%(!.\].)\033'\\
There are a few kludges here. The $GID test for one. It's probably just a case of my not knowing the ins and outs of quoting well enough to assign the expansion of ${(%)(!.15.18)} to a variable. Also right hand truncation (%>str>) fails but, again, it could be my mistake. Using right-padding works quite well though.
To see it in action use:
caption always "%?%F%{.kw}%:%{.wk}%3n %t%{= ww}%? %-Lw%?%F%{+b}%:%{= ww}%?%n%f* %t%{-}%+Lw"
<< Home