what some problems you've run into in the terminal with copy and paste? so far I have:
- pasting a URL with a `&` (or other character) in it without quotes
- pasting in many commands and one in the middle fails
- accidentally leaving in the '$'
- pasting in something with Fancy Quotes instead of normal quotes
- pasting a bash incantation into fish
- not knowing the keyboard shortcut to paste in a new terminal
- how Linux has two different clipboards
@b0rk depending on the terminal, multiline text can be _unpredictable_
@b0rk @benmeier_ I've had text copied out from the terminal *sometimes* have the line wrapping from the terminal copied over with hard carriage returns and sometimes..not
@b0rk nit: It’s not that Linux has two clipboards; it’s that X Window System has typically has two. If you’re used to having two and end up on a Wayland-based system, the loss of middle click the behavior can be a bit jarring.
@matt huh I didn't realize that Wayland didn't have that, thanks! I guess I stopped using the middle click clipboard
@b0rk Using both MacOS and Linux and having to remember to use ⌘-C on Mac and Shift-Ctrl-C on Linux.
@arrjay @b0rk @benmeier_ I also have this issue with tmux/screen. Even worse when you're using it from Mac to shell into something else. I had to rely on iterm2's tmux integration to get some sanity back.
@nashenas @b0rk @benmeier_ yeah, as a konsole user, I *think* it tries to behave differently for it's own paging vs tmux but it's never been super clear, I've often resorted to just piping what I need in temp files and using an out-of-terminal editor.
@benjamingeer @b0rk on that note, i still have no idea how to use the readline Alt-B and Alt-F to go back/forward a word. those just type ∫ and ƒ on a mac!!
@Ezhik @benjamingeer IIRC there's an option in iTerm to make the option key act as a meta key instead of doing the usual mac thing
@b0rk the change in recent bash versions so that they identify and highlight pastes at the command line and don't automatically run the command, even if the paste has a newline in it.
Once you get used to it, it's a useful security feature. But initially it's confusing.
My worst confusion was when I accidentally pasted _just_ a newline, and didn't know why I hadn't got my prompt back, because bash's visual highlight of the paste didn't appear – there were no _printable_ chars to highlight!
@simontatham that's a cool feature, I wonder how they identify pastes
@benmeier_ @b0rk ooh yeah, especially when working with a serial port that is convinced the terminal size is smaller than the window - that one makes me really miss the "block copy" style that cmd prompts have
@b0rk Accidentally pasting a ton of data (which includes newlines) at a shell prompt because you thought something else was in the clipboard, then having to figure out what the heck it did and repair the damage! Worst case, if it was, say, HTML or XML and you are unlucky, it may have truncated some existing files via redirection!
@siracusa that's such a great example thanks!
what shell are you using? trying to get a sense for which shells recognize that you're pasting (and will avoid running the command until you press enter) and which won't
@b0rk there's an escape sequence you can send in terminal output, which requests that the terminal start sending special escape sequences before and after pasted text in the terminal input.
Demonstration: I ran this command, and then pressed the paste key, with the phrase 'pasted text' in the clipboard.
$ echo -ne '\033[?2004h'; cat
^[[200~pasted text^[[201~
Also useful for terminal-based editors to treat indentation specially in pasted text.
@b0rk pasting something and having to go put backslashes where the new lines are
pasting something multiline and having it confuse the "up arrow means back a command" thing, as sometimes up arrow is go up a line and sometimes it's go back a command now.
@b0rk comment characters in Zsh in pasted commands are also handled in surprising ways iirc.
@b0rk I’m using tcsh (because it was the default shell on my first Unix account in 1993, and I’ve stuck with it since!)
@b0rk it's esoteric, but I'm often tripped up by not being able to copy things to the clipboard from `vim` when it's running inside of `tmux`
@b0rk I feel like sometimes I paste and it just runs the command even if I didn't hit enter, but maybe I'm just imagining that?
@LeafyEricScott that's very real! what shell do you use? my impression is that “newer" shells (zsh, fish) do a better job of detecting that you pasted and not running the command (even if there was a newline in there) and older shells will just run it if there's a newline
@b0rk I said this on the other thread, but accidentally typing control-C instead of control-shift-C and thus cancelling the running whatever instead of copying the selected text
also
* related to the two different clipboards, the way the exact behavior of each clipboard is not uniform across the entire GUI but depends on toolkit library, desktop environment, presence or absence of a clipboard management utility, etc. can easily cause someone to paste the Wrong Thing... *especially* for terminal windows, which often aren't using the same toolkit library as everything else
* besides Fancy Quotes, I've seen people get tripped up by copying a Unicode MINUS SIGN instead of ASCII hyphen-minus (usually happens when copying sample code out of a PDF or a webpage). Unicode also has a bunch of variations on . and _ that could be trouble for the same reason
@zwol what do you mean by the exact behaviour of the clipboard not being uniform?
@b0rk related to the fancy quotes issue, i've seen `--` get turned into `—`
@molly0xfff @b0rk So many times! Medium does (did?) it always.
@drgroftehauge @b0rk yeah, i feel like that's where I ran into it too
@hotdogsladies @siracusa We probably need a weekly prompt to make sure we want to allow copying to the clipboard and a second to allow for pasting.
@b0rk
When you copy a few commands out of a website, but then dash-dash pastes as a long-dash. 🙄
@b0rk Like, whether a visible selection on the screen is actually in sync with what's on the PRIMARY clipboard depends on *which libraries were used to implement the application showing the selection* as well as the last few things you did with the mouse. Yes, this is terrible and I hate it
@b0rk the other example that comes readily to mind is that both Emacs and Vim have their own copy and paste system that is poorly integrated with the system clipboard(s) - so, if you paste into them using their built-in paste command instead of a terminal window's paste command, what gets pasted might come from either the internal clipboard or the system clipboard and it's not always predictable which. And, the behavior can be different if you're running the editor in a terminal than if you're running it in its own window.
@zwol ah yeah that's a great one, it took me so long to figure out how to integrate vim's copy and paste with the system clipboard
@hotdogsladies @Gte @siracusa One of the reasons I reluctantly gave up csh:
@hotdogsladies We are going to get _so many_ emails asking how to turn this off.
@roo which shell do you use? on my machine zsh and fish seem to handle multiline pastes well (they'll allow a multiline paste but won't run the code until you press enter)
@b0rk when I say 'multi-line' paste -- I mean one with embedded LF/CR such that the terminal interprets this as a user typing the first line, followed by enter, then the second line.
In a valid paste (multiple, single line commands) results in the shell running command 1 - then running command 2. All is fine.
(1/2)
However, if you paste in say the contents of an email (maybe with quoted text) you cause yourself a mess of pain.
The issue is if you finger fumble, you may not have what you think is in your paste buffer..
I'm mostly on OSX 'terminal' with zsh (defaults) - but this isn't a shell problem, it's a user doesn't know what's in the paste buffer problem mostly.
(2/2)
@roo oh interesting! when I paste something eith embedded newlines in it in zsh, it doesn't run any of the commands.
it sounds like your zsh behaves differently, maybe it's a combination of terminal + shell behaviour?
@roo interesting, i think the terminal has to send a special Paste Code around the paste to protect you from bad pastes and maybe LXTerminal isn't doing that!
@b0rk I may have not been clear. I cannot replicate this in OSX under terminal (local zsh, or over ssh/mosh to a Linux box with bash).
I then tried a virtual machine with Debian/LXTerminal. It also didn't replicate the problem.
I have a very clear memory of being burned by this - multiple times. However, I clearly am not remembering correctly the problem or scenario.
Unfortunately I think you need to ignore all of my comments on this subject, I clearly have an incomplete scenario to describe
@roo i appreciate it even so, it's good to know that it's maybe hard to predict when this is going to happen
@b0rk I never understood why the $ is part of what gets copied to the clipboard
@razze can you say more? (do you mean when copying from the terminal or copying from a webpage?)
@b0rk from Websites, the people that wrote the instructions here for e.g. https://flatpak.org/setup/Rocky%20Linux
@razze hmm when I copy and paste the commands from that page it doesn't include the $ (I just get “sudo dnf install flatpak”), what are you seeing?
it's definitely true that not all websites are careful about making sure that the `$` doesn't get copied though
@b0rk pasting with a return char, when you planned to edit the command before running it 🥲
@chibani what shell / terminal do you use? i'm trying to get a sense for which shells / terminals this happens with
@b0rk I’d say bash and even zsh, but I try to edit the commands in a text editor now, before running them.
@chibani thanks! i see that behaviour in bash too but not in zsh, trying to work out if other people see it in zsh
(screenshot of what it looks for me in zsh)
@b0rk sorry, my memory might be confused. I’ve not encountered this problem for a long time.
@b0rk pasting the wrong stuff.
Whatever I select in the terminal gets auto copied to the buffer. I'm also pretty liberal in my use of select and highlight what I'm currently reading. Every now and then I end up pasting a load of text to the terminal and hope that there wasn't a command buried in it..
@derekmceachern out of curiosity which shell/terminal are you using?
(trying to get a sense for which shells will automatically run commands you paste and which won't, so far it seems like bash/tcsh mostly will except for maybe newer versions of bash and zsh/fish mostly won’t)
@stuartyeates might be good in specific use cases but generally wrong. there's a reason it's called history: the sequence might be important.
@stuartyeates @b0rk export HISTCONTROL=ignoredups
Not exactly what you want, but it should fix the problem.
@conor I was more talking about an application that runs in the background and listen to the clipboard events: each time something new is copied, it is saved, and can be accessed later.
For example, when I'm on a new computer with GNOME, I install something like the Clipboard History extension: https://extensions.gnome.org/extension/4839/clipboard-history/ (there are many others)
Also available for other DEs, e.g. https://www.tecmint.com/best-clipboard-managers-for-linux/
Hard not to have one when you are used to them! 🙂