termsupport.zsh: unwanted execution of commands; interpretation of %-tags [PATCH] #890

Closed
tomterl opened this Issue Jan 31, 2012 · 4 comments

Projects

None yet

4 participants

@tomterl
tomterl commented Jan 31, 2012

termuspport.zsh will execute subcommands on the current commandline; the output will be garbled due to prompt expansion of %-tags in commands like date/printf.

Please apply the following patch:


*** termsupport.zsh.orig    2012-01-31 10:49:57.503119973 +0100
--- termsupport.zsh 2012-01-31 10:50:55.043118110 +0100
***************
*** 24,31 ****
  function omz_termsupport_preexec {
    emulate -L zsh
    setopt extended_glob
!   local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
!   title "$CMD" "%100>...>$2%<<"
  }

  autoload -U add-zsh-hook
--- 24,35 ----
  function omz_termsupport_preexec {
    emulate -L zsh
    setopt extended_glob
!   local CMD_1=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
!   local CMD_2=${2//\$\(/\\\$(} # ')}
!   CMD_1=${CMD_1//\%/%%}          
!   CMD_2=${CMD_2//\%/%%}          
!   #
!   title "${CMD_1}" "%100>...>${CMD_2}%<<"
  }

  autoload -U add-zsh-hook

It might be necessary to escape backticks also, but I don't use these...

kind regards,
Tom

@sorin-ionescu

I had problems with this myself. I rewrote the terminal support in my fork in relation to #377.

@fsaintjacques

This is disastrous, please apply the patch ASAP. Let's say I have a command that modifies his state at each call. The normal behaviour would look like this.

$ echo 1 > herp
$ echo $(cat herp | tee -a herp)
1
$ echo $(cat herp | tee -a herp)
1 1
$ echo $(cat herp | tee -a herp)
1 1 1 1

With the current oh-my-zsh version you get:

$ echo 1 > herp
$ echo $(cat herp | tee -a herp)
1 1
$ echo $(cat herp | tee -a herp)
1 1 1 1 1 1 1 1
$ echo $(cat herp | tee -a herp)
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

tomterl's patch fixes the issue.

@robbyrussell
Owner

Closing this per #2568.

@afrojer afrojer added a commit to afrojer/zsh-config that referenced this issue Aug 6, 2015
@afrojer afrojer bugfix! preexec can't handle printf fmts
Credit for the fix:
    robbyrussell#890

Signed-off-by: Jeremy C. Andrus <jeremy_andrus@apple.com>
cc0eb6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment