2

Sometimes if text that is on the clipboard is pasted into shell and it contains a return character it will execute even though that wasn't the intention. Sometimes even multiple lines may be pasted in by mistake and then unintended commands could be run.

I understand in a perfect world, these mistakes would never happen, but is there a way to prevent this to avoid the risk of human error?

3

If you're using PuTTY on Windows, here's an AutoHotKey script which will detect if you're trying to paste something into PuTTY that has one or more newlines and if so will confirm you're wanting to do so.

Tip: you can hit the space bar or keypad enter key as an easy way to press "Yes".

Note: this script uses ctrl+v to paste into PuTTY, but you could replace ^v with RButton if you wanted to hook this into the right-click-to-paste default functionality of PuTTY.

#ifwinactive ahk_class PuTTY

    ^v::

        var := clipboard
        var := RegExReplace(var, "\r\n?|\n\r?", "`n", lineNum)

        If(lineNum>0)
        {
            MsgBox, 4, , There are one or more newlines in what you're pasting, are you sure you want to continue?
            IfMsgBox Yes
                SendInput {Shift down}{Insert}{Shift Up}
            else IfMsgBox No
                return
        }
        else
        {
            SendInput {Shift down}{Insert}{Shift Up}
        }

    return

#ifwinactive
| improve this answer | |
2

Use Ctrl+X Ctrl+E (“edit current line”) before pasting. This will start your default editor; you have to save and quit, then the pasted commands are executed.

| improve this answer | |
-1

I had the same problem, but then I made a habit of always copying a single word into clipboard, after I'm done pasting. If you force this habit 3-4 times then your hands will do it automatically from there on. I have never mis-pasted since I began this routine.

| improve this answer | |
  • this question is not about mis-pasting something unintended, but pasting something intended with an unintended return (linefeed, enter) – törzsmókus Jul 2 '18 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.