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

Re: question about quoting % in preexec



Andy Spiegl wrote:
> I am using the following preexec-function to display the currently running
> process in my xterm-title:
> 
>       preexec () {
>         print -Pn "\033]0;%n@%m <${(Vq)2}> %~\007"
>         print -Pn $icontitle
>       }
> 
> But if I run a command with "%" in the arguments, e.g.:
>  date "+%Y-%m-%d %H:%M:%S"
> 
> it leads to very unwanted results because zsh interprets it as variables.
> How can I avoid this?  I suppose I have to quote the %s but how?

It would be easier to just split it across extra print commands:
  print -Pn '\033]0;%n@%m <'
  print -rn -- "${(Vq)2}"
  print -Pn '> %~\007'

The -r option does raw output so no escapes are interpreted.

Oliver



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