Paste into SSH terminal capitalizes last character and doesn't allow me to edit it [closed]
Asked Answered
T

2

14

I'm running Terminal on my Mac and SSH'ing into a Linux host. When I paste text, it will often capitalize the last character of whatever I'm pasting, and the cursor will turn gray and I won't be able to type additional characters or delete characters from whatever I pasted. My only two options at that point are to either ^C to break onto the next line without running the command, or hit enter and run the messed up command.

It doesn't happen 100% of the time. If I copy something and then repeatedly paste it into the shell, I'll see this issue occur about 50% of the time. I have no idea why it's apparently non-deterministic like this. I thought this might also be due to "bracketed paste" issues, but no matter how many times I run the commands printf '\e[?2004l' and set enable-bracketed-paste off, the issue persists. It even persists when I exit and re-SSH to the host with a fresh SSH session, so I know it's not due to some sort of leftover bad state in the SSH session. Can someone please help??? This is killing my productivity!

Here's an example of what the pasted text looks like when the issue occurs:

Paste with issue

(The text I was trying to paste was ParameterKey=Stage with a lowercase e at the end)

I'm aware that other questions have been asked along these lines, like this one from Stack Exchange, but none of the answers on any of these posts have worked for me, so I think my problem may be slightly different than those...

Takamatsu answered 21/12, 2019 at 0:27 Comment(9)
Small Update: I've noticed that after I paste, I can press the i key and it will then allow me to edit the text I pasted. This is the same key you'd use to enter "insert" mode in vim, so now I'm thinking it might have something to do with vim, but I still don't understand how that'd be possible given that the issue happens even on a fresh terminal where I've never opened vim.Takamatsu
Which shell you are using?Fulvia
It looks like I'm just using zshTakamatsu
To troubleshoot, 1) Try to find which shell you use by running echo zsh=$ZSH_VERSION bash=$BASH_VERSION 2) Run ssh -t linux-host bash, then paste to see if you still have problems 3) Run ssh linux-host followed by set -o emacs, then paste. 4) Run ssh -t linux-host vim then type i, then paste.Linseylinseywoolsey
1) Output: zsh=5.9 bash= 2) Running ssh -t <linux-host> bash seems to fix it! 3) Running set -o emacs also seems to fix it! 4) Running ssh -t <linux-host> vim creates a very weird terminal experience where I'm not able to run commands or anything, it just looks like I'm in a vim editorTakamatsu
I mentioned vim for troubleshooting purposes, trying to see if it can display all characters pasted. Now run ssh -t linux-host zsh --no-rcs then paste. If this fixes the problem, that could mean there are issues in initialization files like ~/.zshrc, ~/.zlogin etc.Linseylinseywoolsey
Yes, that also seems to fix the issue! I think this clearly indicates that it's an issue with my ~/.zshrc file, but I still have no idea what exactly it could be. My company has a whole bunch of stuff that they've automatically included in that file, so it must be something in all of that that's causing the issue... though I've asked my colleagues if they've experienced the same behavior and they say they haven't. Is there a particular culprit in the zshrc file that you'd recommend I look for?Takamatsu
Stack Overflow is for programming questions, not questions about using or configuring Unix and its utilities. Unix & Linux or Super User would be better places for questions like this.Selfimprovement
I believe I've finally found the solution to the problem - adding unset zle_bracketed_paste to the end of my ~/.zshrc file seems to have fixed it! I had tried using set enable-bracketed-paste off previously, but it didn't work... I guess I just needed to use the correct command to disable bracket paste.Takamatsu
M
0

Check your ZSH config

cat ~/.zshrc

Check if in plugins=(...) you find safe-paste. If it's there, edit the config and delete safe-paste.

if grep -q "safe-paste" "~/.zshrc"; then   # checks if str in contained in file
    sed -e s/safe-paste//g -i ~/.zshrc     # if so, it replaces the str with nothing
fi

As a one liner:

if grep -q "safe-paste" "~/.zshrc"; then; sed -e s/safe-paste//g -i ~/.zshrc; fi
Minhminho answered 8/1, 2020 at 12:42 Comment(7)
Thanks for the response. Unfortunately there is no plugins or safe-paste anywhere in my ~/.zshrc file.Takamatsu
Is there a way to tell if safe-paste mode is on? Maybe it's being turned on somewhere else?Takamatsu
@Takamatsu ok do you paste with ctrl+v or ctrl+shift+v? Just trying to narrow it down nowMinhminho
It's just Command+V, no Shift needed (I'm using a Mac, so I guess that'd be the equivalent of just Ctrl+V)Takamatsu
By the way, this same behavior happens regardless of whether I use Command+V or Command+Shift+VTakamatsu
What is the source of the text in the clipboard that you are pasting? I.e. if you copy from a simple text editor or terminal window does the behaviour still happen?Abba
Yes, I can literally just copy text from the terminal itself and paste it into itself to reproduce the behaviorTakamatsu
I
0

Your keybindings are not working for you. You might have tried customizations with Oh My Zsh or not, but anyway bindkey commands mess up your workflow with Terminal.

You can start all over again configuring your zsh environment with rm ~/.zshrc.

Then when you start zsh again (by logging in), you'll see:

This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

Select this sequence of choices to have the following line configured in your new ~/.zshrc: 1, 3, 1, e, 0, 0

bindkey -e
Indefectible answered 30/7 at 12:34 Comment(6)
I have not used Oh My Zsh before, but I will check it out. When I use bindkey -e, the paste behavior changes... now it doesn't sporadically capitalize the last character when I paste, instead it sporadically adds a ~ after the text that I pasted! Thanks for trying to help, but this seems to have just replaced one paste problem with another - so frustrating!Takamatsu
That ~ is a sign that vi key bindings are still at play. ~ is the vi command to change case. Verify these files: /etc/zshenv /etc/zprofile /etc/zshrc /etc/zloginIndefectible
I believe I've finally found the solution to the problem - adding unset zle_bracketed_paste to the end of my ~/.zshrc file seems to have fixed it!Takamatsu
You can add that as an answer to your own question, to resolve it on SO.Indefectible
I can't because someone closed the question before I could post the answerTakamatsu
I voted to re-open this question so you can provide the answer. Answered questions have closure.Indefectible

© 2022 - 2024 — McMap. All rights reserved.