Conversation

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

18
0
0

@b0rk depending on the terminal, multiline text can be _unpredictable_

1
0
0

@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

2
0
0

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

1
0
0

@matt huh I didn't realize that Wayland didn't have that, thanks! I guess I stopped using the middle click clipboard

0
0
0
@b0rk Running a GUI program, copying something to the clipboard, closing the program and having the clipboard be empty. Unfortunately no concrete example for you off the top of my head, but it is something I run into fairly often. I've always just dismissed it as one of the "quirks" of having a non-standard desktop environment...
1
0
3

@b0rk Using both MacOS and Linux and having to remember to use ⌘-C on Mac and Shift-Ctrl-C on Linux.

1
0
0

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

1
0
0

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

0
0
0

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

1
0
0

@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

0
0
0

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

1
0
0

@simontatham that's a cool feature, I wonder how they identify pastes

1
0
0

@arrjay @b0rk yeah, outside of a HEREDOC, it can be very prompt- and environment dependent whether new lines are kept, escaped, or trigger execution. And this can sometimes be odd when going through proxies, KVM, or other tunneled layers.

1
0
0

@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

0
0
0

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

3
0
0

@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

1
0
0

@siracusa @b0rk You should have put a trigger warning on this toot.

0
0
0

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

1
0
0

@simontatham thank you, I thought you'd know the answer :)

0
0
0

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

0
0
0

@b0rk comment characters in Zsh in pasted commands are also handled in surprising ways iirc.

0
0
0

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

1
0
0

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

0
0
0

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

1
0
0

@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

0
0
0

@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

1
0
0

@zwol what do you mean by the exact behaviour of the clipboard not being uniform?

1
0
0

@b0rk related to the fancy quotes issue, i've seen `--` get turned into `—`

1
0
0

@molly0xfff @b0rk So many times! Medium does (did?) it always.

1
0
0

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

1
0
0

Mauricio Teixeira 🇧🇷🇺🇲

Edited 4 months ago

@b0rk
When you copy a few commands out of a website, but then dash-dash pastes as a long-dash. 🙄

0
0
0

@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

1
0
0

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

1
0
0

@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

0
0
0

@hotdogsladies We are going to get _so many_ emails asking how to turn this off.

0
0
0

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

1
0
0

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

1
0
0

@b0rk

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)

1
0
0

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

0
0
0

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

1
0
0

@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

1
0
0

@roo i appreciate it even so, it's good to know that it's maybe hard to predict when this is going to happen

0
0
0

@b0rk I never understood why the $ is part of what gets copied to the clipboard

1
0
0

@razze can you say more? (do you mean when copying from the terminal or copying from a webpage?)

1
0
0

@b0rk from Websites, the people that wrote the instructions here for e.g. https://flatpak.org/setup/Rocky%20Linux

1
0
0

@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

0
0
0

@b0rk pasting with a return char, when you planned to edit the command before running it 🥲

1
0
0

@chibani what shell / terminal do you use? i'm trying to get a sense for which shells / terminals this happens with

1
0
0

@b0rk I’d say bash and even zsh, but I try to edit the commands in a text editor now, before running them.

1
0
0

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

1
0
0

@b0rk sorry, my memory might be confused. I’ve not encountered this problem for a long time.

1
0
0

@chibani no worries these things are so hard to track down!

0
0
0

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

1
0
0

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

0
0
0

@b0rk

Cut and pasting a command block so often it pushes everything else out of the command history.

One paste should be history item and identical history items should not count for history size.

2
0
0

@stuartyeates might be good in specific use cases but generally wrong. there's a reason it's called history: the sequence might be important.

0
0
0

@stuartyeates @b0rk export HISTCONTROL=ignoredups
Not exactly what you want, but it should fix the problem.

0
0
0

@conor @b0rk that's good there are many "clipboard managers" available, e.g. as a plug-in for the DE. Not sure why it is not natively integrated in the DE.

1
0
0
@matttbe There's xclip, if you count that as a "clipboard manager". I don't see how a "clipboard manager" would solve the problem however.
1
0
0

@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! 🙂

1
0
0
@matttbe that just amounts to a bandaid, not actually solving the problem of stopping the clipboard being emptied when the program closes. Also, not entirely sure I /want/ something to have a history of what I have in my clipboard...
0
0
1