4 ms·
I always just type "#" first before pasting... That way it is just a comment I can inspect before running
by umvi 7y ago
I always just type "#" first before pasting... That way it is just a comment I can inspect before running
- hackmiester 7y agoHere, paste this into your terminal: echo "hello" echo "lol" ; sudo sl -rf / (In case it's not obvious, the # trick will not help you.)
- umvi 7y agoTrue, the comment trick does not work for multi-line pastes
- jtbayly 7y agoSo... don’t paste it in my terminal?
- hackmiester 7y agoheh, yes. Admittedly, immediately after posting, I did change it from 'rm', which would not be a good idea to run, to 'sl', which ... well, try it (or `man sl`), it's fun.
- dredmorbius 7y agoIf you're using Readline (most Bash or similar shells do), then C-x C-e will invoke the editor, and you can paste the output into that. Pray for no escape, bang, or control sequences. (Alternatively: "r! cat <paste> <ctrl>-D" will read into a vim session.) Examine the output, trim the unwanted / dangerous bits, and run (or save to a file/script). Since I run what are ... generously ... considered "bash one-liners" all the time, that key sequence is locked into my muscle memory. It's a convenient way to invoke an editor immediately and run code from it.
- majewsky 7y ago> :r! cat <paste> <ctrl>-D Alternatively, call a utility that can read the clipboard directly. For Xorg: :r! xsel -b For Wayland: :r! wl-paste
- dredmorbius 7y agoThat depends on whether or not the clipboard is directly accessible or not. When invoking an editor remotely via SSH, for example, it's not. Though there's often the ability to past into the controlling terminal locally. I do this frequently on Android via Termux, ssh'ing to remote hosts.