[-- Attachment #1: Type: text/plain, Size: 602 bytes --] Hey, The zsh manual says about `preexec` that: "the string that the user typed is passed as the first argument". This mostly work as expected, but I found cases where there is some expansion going on. In order to debug the issue I'm seeing, I have this zsh code run from my zshrc: ```zsh echo_preexec_command() { echo "$1" | cat -A } autoload -U add-zsh-hook add-zsh-hook preexec echo_preexec_command ``` Now if I type `echo \b` the string `echo ^H$` is printed (i.e. `\b` was replaced by `^H`). This does not happen when using `fc -nl -1`. How can I get the same inside `preexec`? Thanks!
On Sun, 2 Jun 2019 at 16:47, Sylvia Gough <q0h8xdveje@gmail.com> wrote: > ... > Now if I type `echo \b` the string `echo ^H$` is printed (i.e. `\b` was > replaced by `^H`). > This does not happen when using `fc -nl -1`. > > How can I get the same inside `preexec`? > > Thanks! It is the echo in the hook that does the conversion \b -> ^H. Use -E option with echo to prevent this. -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org
[-- Attachment #1: Type: text/plain, Size: 676 bytes --] Thanks, that works! On Sun, Jun 2, 2019 at 7:03 PM Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote: > On Sun, 2 Jun 2019 at 16:47, Sylvia Gough <q0h8xdveje@gmail.com> wrote: > > ... > > Now if I type `echo \b` the string `echo ^H$` is printed (i.e. `\b` was > > replaced by `^H`). > > This does not happen when using `fc -nl -1`. > > > > How can I get the same inside `preexec`? > > > > Thanks! > > It is the echo in the hook that does the conversion \b -> ^H. Use -E > option with echo to prevent this. > > -- > Sebastian Gniazdowski > News: https://twitter.com/ZdharmaI > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin > Blog: http://zdharma.org >
When printing content outside of your control, use `print -r -- $1` or `echo -E - $1`. Plain `echo -E $1` won't work if the argument is `-n` or some other valid flag. Roman.
[-- Attachment #1: Type: text/plain, Size: 296 bytes --] Good point, thanks! On Mon, Jun 3, 2019 at 12:26 PM Roman Perepelitsa < roman.perepelitsa@gmail.com> wrote: > When printing content outside of your control, use `print -r -- $1` or > `echo -E - $1`. Plain `echo -E $1` won't work if the argument is `-n` > or some other valid flag. > > Roman. >