4 ms·
Bash, via GNU Readline, has an option that sidesteps this issue: enable-bracketed-paste (On) When set to On, readline will configure the terminal in
by RVuRnvbM2e 6y ago
Bash, via GNU Readline, has an option that sidesteps this issue:
enable-bracketed-paste (On)
When set to On, readline will configure the terminal in a way
that will enable it to insert each paste into the editing buf‐
fer as a single string of characters, instead of treating each
character as if it had been read from the keyboard. This can
prevent pasted characters from being interpreted as editing
commands.
Effectively it means that even if you paste garbage into the terminal you still have to hit enter before the command is interpreted.
- loloquwowndueo 6y agoThis won’t help for the kind of clueless blind-paste people who run into this issue in the first place - they don’t know what they are doing, is the actual problem. They’ll just paste whatever, hit enter, and then ask for support because nothing works :)
- macintux 6y agoI've been a UNIX admin & developer for 25 years. I still on occasion accidentally paste the wrong text into the terminal. (Admittedly, I think it only ever happens at home now, because everything I do on a work system scares the hell out of me.)
- oconnor663 6y agoThis is the real solution! I think every shell supports "safe paste" in some way. For example, here's something for Zsh: https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/safe-paste/safe-paste.plugin.zsh https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/safe-... This works great in combination with another advanced feature, "edit command" or "edit and execute command". Once you've pasted a command into the terminal, even a multiline command with safe paste, you can have the shell open your $EDITOR to edit the command, and automatically put the result right back into the shell (or just run it). This is available in Bash by default as ctrl-x ctrl-e. (And as someone else pointed out below, if you don't want to enable safe paste, you can open the editor first on a blank command line and paste into that. But really we should all enable safe paste.)
- mjevans 6y agoThank you, I think I've accidentally activated this mode without knowing _or wanting_ it when muscle memory for copy/paste happens while using a windows workstation but E.G. putty. Now I know it's a mode and that ctrl-e can undo it.
- kzrdude 6y agoIt should be enabled by default, so it would truly help. By the way, doesn't this solve the sudo issue too? That where a password prompt swallows the rest of the pasted lines.
- penguin_booze 6y agoTIL: man readline is a gold mine!