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

Re: /usr/bin/printf

On Feb 12, 10:04pm, Matthew Flaschen wrote:
} Mikael Magnusson wrote:
} > This is because your preexec() function is broken and is outputting
} > the newline from the cmdline without escaping it
} 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?

The problem is that $1 is first expanded by the command parser and then
passed to "print".  When $1 contains the substring "\n", "print" turns
that into a newline.  So you need to quote the value of $1 against
further expansion by "print".

preexec () { print -Pn "\e]0;%n@%m: ${(q)1}\a" }

The (q) tells zsh to insert a backslash before any special characters
that appear in the value of $1, including the backslash in "\n".  Then
"print" strips the extra backslashes off again and the final output is
the original string.

Or, well, it would be, except there's that -P option there, which will
turn any %x (for any x) in your $1 into some sort of prompt expando.
So you really need to do this in two steps, one to do the prompt
expansion and one to handle the value of $1.

preexec () { print -Pn "\e]0;%n@%m: "; print -n "${(q)1}\a" }

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