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

Re: preexec and multi-line command.



On 20 February 2010 20:20, Piotr Karbowski <jabberuser@xxxxxxxxx> wrote:
> Hi there!
>
> I have starge problem after I added preexec function to my zshrc to
> add in terminal TITLE what is running inside.
>
> ## cut here
> case $TERM in
>        rxvt*|xterm|nxterm|gnome|screen)
>        precmd () {print -Pn "\e]0;%n@%m: %~\a"}
>        preexec () { print -Pn "\e]0;$1 [%n@%m: %~]\a"}
>        ;;
> esac
> ## cut here
>
> Issue is that when I doing something multiline, I got:
>
> ## cut here
> slashbeast@ragnarok ~ % echo 1\
> slashbeast@ragnarok ~ > 2\
> slashbeast@ragnarok ~ > 3\
> slashbeast@ragnarok ~ >
>
> 2
> 3
>  [slashbeast@ragnarok: ~]123
> slashbeast@ragnarok ~ %
> ## cut here
>
> How can I fix it?

You need to quote $1 properly, how to do that depends on your
terminal. I use this:
    if [[ $TERM = rxvt-unicode ]]; then
      printf '\0\e:\e]0;%s\007' ${${${1//$'\x00'/\^@}//
/\\n}//(#m)[$'\x00'-$'\x1f']/$'\x16'$MATCH}

-- 
Mikael Magnusson



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