Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste fails when using bracketed-paste-magic #102

Closed
SeanTAllen opened this issue Jan 30, 2016 · 32 comments
Closed

Paste fails when using bracketed-paste-magic #102

SeanTAllen opened this issue Jan 30, 2016 · 32 comments

Comments

@SeanTAllen
Copy link

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
Copy link
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
Copy link

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
Copy link
Member

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

@SeanTAllen
Copy link
Author

@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
Copy link

ronjouch commented Feb 1, 2016

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

Yes too.

@ericfreese
Copy link
Member

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

@ronjouch
Copy link

ronjouch commented Feb 1, 2016

@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
Copy link

ronjouch commented Feb 1, 2016

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)

@alagane
Copy link

alagane commented Feb 1, 2016

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
Copy link

ronjouch commented Feb 1, 2016

@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)

@alagane
Copy link

alagane commented Feb 1, 2016

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
Copy link

bricewge commented Feb 1, 2016

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
Copy link

ronjouch commented Feb 1, 2016

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
Copy link
Author

@ronjouch i'm not using tmux.

@ronjouch
Copy link

ronjouch commented Feb 1, 2016

@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
Copy link
Author

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
Copy link
Author

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
Copy link

ronjouch commented Feb 2, 2016

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

Solves the problem for me too!

@SeanTAllen
Copy link
Author

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
Copy link
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
Copy link
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 milestones: v0.1.1, v0.1.0 Feb 7, 2016
@ericfreese ericfreese changed the title Paste to terminal problem with oh-my-zsh Paste fails when using bracketed-paste-magic Feb 7, 2016
@ericfreese
Copy link
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
Copy link
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-*'

@ericfreese
Copy link
Member

ericfreese/zsh@ff23295

@ronjouch
Copy link

@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.

@alagane
Copy link

alagane commented Feb 14, 2016

It works for me too ;)

@ericfreese
Copy link
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

@ronjouch
Copy link

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.

@louisabraham
Copy link

Hi, I followed the instructions at https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md#oh-my-zsh

Pasting is slow, but

autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
zstyle ':bracketed-paste-magic' active-widgets '.self-*'

solves it.

I thought v0.2.7 and above don't require this workaround, but I use v0.5.0.

@leehambley
Copy link

Confirmed the workaround from @louisabraham works.

I'm on the latest versions of everything, as far as I know, but I don't know how to check ZLE/etc

ZSH: 5.7.1
Oh-My-Zsh: 095d56b5ea44988c83d0be501e70f (September 19 2019)

@ericfreese
Copy link
Member

@louisabraham @leehambley This issue is pretty old and is about paste failing entirely. If you're just seeing it behave slowly, you might be better off looking at this issue: #238 (comment)

@leehambley
Copy link

Issue seems to be Alacritty specific - alacritty/alacritty#2795

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

No branches or pull requests

7 participants