Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: /usr/bin/printf



In the last episode (Feb 12), Matthew Flaschen said:
> Mikael Magnusson wrote:
> > This is because your preexec() function is broken and is outputting the
> > newline from the cmdline without escaping it, which makes your terminal
> > stop reading the title, and the rest of the command line is just echoed. 
> > This is kind of hard to figure out the first time.
> 
> Okay, here's my preexec.  I admit I don't understand this syntax yet:
> 
> preexec () { print -Pn "\e]0;%n@%m: $1\a" }
> 
> I got it from
> http://web.archive.org/web/20071224181948/www.princeton.edu/~kmccarty/zsh.html
> 
> Do you know how I would correct it?

Here's what I use.  Possibly overkill.  The extra escape string in the
$+WINDOW=1 case truncate the window names within screen to 10 chars so that
"^A W" can still display a lot of titles even if your commandline in window
1 is long.  Truncating the title itself to 100 characters helps if you're
editing a huge commandline (say you manually expanded a 500-arg wildcard for
some reason; no need to send all that to xterm).


# strip control chars and replace with "."
# result is returned in $reply
function _strip()
{
  local i=1
  reply=$1
  while (( i <= $#1 )) ; do
    [[ $reply[i] > $'\C-_' && $reply[i] < $'\C-?' ]] || reply[i]="."
    (( i ++ ))
  done
}

SHOST=$(print -P %m)

if [[ $+WINDOW = 1 && $TERM = screen* ]] ; then
  preexec () { _strip $1 ; echo -En "k${reply[1,10]:gs/ /_/}\\]0;$SHOST: ${reply[1,100]}" }
else
  case $TERM in
    xterm*|screen*)
      preexec () { _strip $1 ; echo -En "]0;$SHOST: $reply[1,100]" } ;;
  esac
fi


-- 
	Dan Nelson
	dnelson@xxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author