Paste fails when using bracketed-paste-magic #102

Closed
SeanTAllen opened this Issue Jan 30, 2016 · 28 comments

5 participants

@SeanTAllen

On the v0.1.x branch. Commit 6dd93ed.

OSX. El Capitan. Tried with both terminal and iTerm.

zsh version: zsh 5.2 (x86_64-apple-darwin15.0.0) has problem
zsh version: zsh 5.0.8 (x86_64-apple-darwin15.0) does not have the problem

When I paste anything to the terminal, nothing visibly happens. Terminal stops accepting an input until I ctrl-c at which point I get a new prompt.

Configuration available at https://github.com/SeanTAllen/dotfiles/blob/master/.zshrc

Problem doesn't happen when not using oh-my-zsh. I'm going to try to track the issue down. Haven't had any luck yet.

@ericfreese
zsh-users member

I'm going to try to track the issue down.

Sounds good, let me know when you have more details.

@ericfreese ericfreese added this to the v0.1.0 milestone Jan 31, 2016
@ronjouch

I confirm the problem on zsh 5.2 within tmux 2.1 on Arch Linux x64, with oh-my-zsh and a few plugins (full configuration details at #101 (comment) ).

"When I paste anything to the terminal, nothing visibly happens. Terminal stops accepting an input until I ctrl-c at which point I get a new prompt" is my exact problem too.

@ericfreese
zsh-users member

Does this problem go away when you disable the autosuggestion plugin?

@SeanTAllen

@ericfreese yes. it only happens with the combo of zsh-autosuggestion, oh-my-zsh and zsh 5.2.

In my experience, switching to zsh 5.0.8 or not using oh-my-zsh or turning off zsh-autosuggestion all fix the problem.

@ronjouch

Does this problem go away when you disable the autosuggestion plugin?

Yes too.

@ericfreese
zsh-users member

@ronjouch Do you still have this problem now that you're no longer using zle-line-init?

@ronjouch

@ronjouch Do you still have this problem now that you're no longer using zle-line-init?

Yes. Additional data point: problem doesn't happen out of tmux. To recapitulate all that I know,

  • Problem isn't dependent on loading with autosuggest_start or zle -N zle-line-init autosuggest_start
  • Problem concerns both Ctrl+Shift+V (clipboard paste), and a middle-click (X selection paste)
  • On my work machine (Ubuntu 14.04.3 LTS, zsh 5.2, tmux 2.1 + oh-my-zsh),
    • In tmux,
      • With zsh-autosuggestions loaded: problem
      • Without zsh-autosuggestions loaded: no problem
    • Out of tmux,
      • Problem never happens out of tmux (even with zsh-autosuggestions loaded). Tmux 2.1 / zsh 5.2, empty .tmux.conf, started with this snippet from the arch wiki in .zshrc:
  • On my home machine (Arch Linux, zsh 5.2, tmux 2.1 + oh-my-zsh),
    • In tmux and out of tmux,
      • With zsh-autosuggestions loaded: problem
      • Without zsh-autosuggestions loaded: no problem
if [[ -z "$TMUX" ]] ;then
    ID="`tmux ls | grep -vm1 attached | cut -d: -f1`" # get the id of a deattached session
    if [[ -z "$ID" ]] ;then # if not available create a new one
        tmux new-session -d zsh
        tmux split-window -h
        tmux select-pane -L
        tmux resize-pane -Z
        tmux -2 attach-session -d
    else
        tmux attach-session -t "$ID" # if available attach to it
    fi
fi
@ronjouch

EDIT: what's below worked around the problem on my work machine (Ubuntu 14.04LTS, zsh 5.2, tmux 2.1), but the problem persists on my home machine (Arch Linux, zsh 5.2, tmux 2.1)


@ericfreese got it! At line 4 of my tmux startup script above, I do tmux new-session -d zsh:

if [[ -z "$TMUX" ]] ;then
    ID="`tmux ls | grep -vm1 attached | cut -d: -f1`" # get the id of a deattached session
    if [[ -z "$ID" ]] ;then # if not available create a new one
        tmux new-session -d zsh # <-- here be dragons ----------------------------------
        tmux split-window -h
        tmux select-pane -L
        tmux resize-pane -Z
        tmux -2 attach-session -d
    else
        tmux attach-session -t "$ID" # if available attach to it
    fi
fi

If instead of tmux new-session -d zsh I do tmux new-session -d (thus "attaching to the current terminal" instead of spinning a new zsh, as per the man page below), the problem disappears: pasting works as expected. Below is what tmux's man page says; do you understand what's going on?

 new-session [-AdDEP] [-c start-directory] [-F format] [-n window-name] [-s session-name]
             [-t target-session] [-x width] [-y height] [shell-command]
    Create a new session with name session-name.

    The new session is attached to the current terminal unless -d is given. 
    window-name and shell-command are the name of and shell command to execute
    in the initial window. If -d is used, -x and -y specify the size of the initial window
    (80 by 24 if not given).

@SeanTAllen you haven't mentioned tmux so far, but could you be in a similar position ("nested" zsh instances, not sure "nested" is the right word)

@Minizarbi

I have the same problem, without tmux.
I use urxvt, and when I middle click it doesn't paste with zsh-autosugg (it does without).
Or it pastes strange things, like a ~ sometimes.
Also, if I copy just spaces, it pastes the spaces.

Plugins:
OhMyZsh with:
fishy theme
git
command-not-found
zsh-syntax-highlighting
zsh-autosuggestions (0.1.x)

@ronjouch

@Minizarbi I narrowed down on my case and precised what's wrong for me a few seconds before you posted, can you check if your case could relate to mine in some way? ("nested" zsh instances, not sure "nested" is the right word)

@Minizarbi

I can't answer you certainly, I think it's a nested zsh instance, I have not really starting script so I can't change the script, and it worked without zsh-autosuggestions.

@bricewge

I also have this issue with termite and antigen and as @Minizarbi I don't seems to have a nested zsh instance.
Here is my configuration if needed.

@ronjouch

Update: my comment above ( #102 (comment) , fiddling with tmux new-session behavior) worked around the issue on my work machine (Ubuntu 14.04LTS, zsh 5.2 + oh-my-zsh, tmux 2.1), but the problem persists on my home machine (Arch Linux, zsh 5.2 + oh-my-zsh, tmux 2.1)

@SeanTAllen

@ronjouch i'm not using tmux.

@ronjouch

@ronjouch i'm not using tmux.

Yeah, I noticed I'm having the problem too on my home machine, both in and out of tmux :-/ . I updated my case at #102 (comment)

@SeanTAllen

I'm not aware of any "nested zsh" problem. unless there is one in oh-my-zsh.

I'm not starting any other shells that i know of, i'm not using tmux or anything else.

@SeanTAllen

Removing this code from oh-my-zsh's misc.zsh seems to solve the problem:

if [[ $ZSH_VERSION != 5.1.1 ]]; then
  for d in $fpath; do
    if [[ -e "$d/url-quote-magic" ]]; then
      if is-at-least 5.1; then
        autoload -Uz bracketed-paste-magic
        zle -N bracketed-paste bracketed-paste-magic
      fi
      autoload -Uz url-quote-magic
      zle -N self-insert url-quote-magic
      break
    fi
  done
fi

I need to test further.

@ronjouch

Removing this code from oh-my-zsh's misc.zsh seems to solve the problem

Solves the problem for me too!

@SeanTAllen

Ok, specifically, it is just this:

      if is-at-least 5.1; then
        autoload -Uz bracketed-paste-magic
        zle -N bracketed-paste bracketed-paste-magic
      fi

bracketed-paste-magic appears to be causing the issue.

@ericfreese I'm really new to zsh so I don't know why they would interact poorly. I hope though that this is enough for you to go on. Please let me know if you need me to do any testing, change anything etc to get you more info.

@ericfreese
zsh-users member

@SeanTAllen @ronjouch This is great! Thanks for digging so deep into this. I'll see what I can do with this new info.

@ericfreese
zsh-users member

This is the minimal .zshrc that causes the problem for me:

autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

Trying to paste into the command line gives the error:

bracketed-paste-magic:zle:41: not enough arguments for -U

Edit: Updated for v0.2.0

@ericfreese ericfreese modified the milestone: v0.1.1, v0.1.0 Feb 7, 2016
@ericfreese ericfreese changed the title from Paste to terminal problem with oh-my-zsh to Paste fails when using bracketed-paste-magic Feb 7, 2016
@ericfreese
zsh-users member

Whew! After digging into the guts of bracketed-paste-magic it looks like this problem is due to this line calling zle without the -w flag to set $WIDGET appropriately. Not sure if this is a bug in bracketed-paste-magic, but it sure seems like it.

bracketed-paste-magic also makes use of the undo widget here, which could cause more issues for anyone who's configured this plugin to bind the undo widget.

@ericfreese
zsh-users member

Until we get to the bottom of who's at fault here, setting active-widgets to use the dot-prefixed versions of whichever widgets you want to be active should provide a decent workaround.

zstyle ':bracketed-paste-magic' active-widgets '.self-*'

So, for example, here's a minimal .zshrc that fixes the problem:

autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
zstyle ':bracketed-paste-magic' active-widgets '.self-*'
@ronjouch

@ericfreese thanks for following up and documenting the issue+workaround in README 👍

Just migrated my ~/.zsh-autosuggestion and autosuggest_start to the latest 0.2.2 in OMZ_CUSTOM_FOLDER started as an omz plugin, plus your workaround, everything seems okay and the ZSH_AUTOSUGGEST_ options I use still work as expected.

@ericfreese ericfreese added has-workaround and removed bug labels Feb 14, 2016
@Minizarbi

It works for me too ;)

@ericfreese
zsh-users member

I believe v0.2.6 should no longer require the workaround. Please give that a shot.

Edit: v0.2.6 had a typo. Try v0.2.7

@ericfreese ericfreese closed this Feb 15, 2016
@ronjouch

I believe v0.2.6 should no longer require the workaround. Please give that a shot.
Edit: v0.2.6 had a typo. Try v0.2.7

@ericfreese confirmed! v0.2.7 seems to be the golden release ^^. Thanks for keeping up with the issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment