Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: bracketed paste mode in xterm and urxvt

On 06/03/2015 10:35 AM, Jesper Nygårds wrote:
> I have a hard time figuring out how this is useful. Could you guys post
> some examples of what you are using this function for?

Bracketed paste is of course useful for copy/paste in the terminal.

When pasting in a terminal, normally the shell receives the raw input,
including newlines, quotes and the like. There's no difference between
typing and pasting. For example, often you want to select a code snippet
from a web page, and the page might include extra markup that breaks the
command and/or runs it directly even when you're careful.

Besides being dangerous, it's also annoying that you need to quote the
pasted text manually. For example

wget <paste url>

will often fail if the url contains ?. You need to edit the command and
quote it. Annoying.

Bracketed paste is implemented by the terminal+shell: the terminal sends
control sequences during paste that allow the shell to know that
something is being paste as opposed to being typed. The shell can then
act accordingly.

In the 'safe-paste' oh-my-zsh plugin, the pasted text is not directly
executed: the newlines are inserted as a multi-line command instead,
which allow you to see the command before executing it instead.

In the posted examples, you can actually chose if the pasted text should
be literal or quoted. With quoted paste, you can pass urls and similar
blocks of text as command arguments without having to fudge it.

Messages sorted by: Reverse Date, Date, Thread, Author