Terminal – Safely Pasting Text in MacOS

terminal

I paste filenames/etc into Terminal all the time, and occasionally the contents of the clipboard isn't what I expect.

Often the result is several hundred lines of text (eg, source code) pasted into the command prompt, triggering god only knows what nastiness.

Is there some way to prevent bash from blindly executing whatever I paste in? I wish it would just paste the text, and let me decide after if I wanna execute it.

Best Answer

Assuming you are using bash: If you activate emacs shortcuts with set -o emacs you can also use Emacs to edit the command line:

  • Type Ctrl-XCtrl-E at the prompt to start Emacs
  • Paste and edit your clipboard content into the Emacs buffer
  • Use Ctrl-XCtrl-C to exit Emacs and automatically run the command(s).