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

bracketed paste

Has anyone tried enabling the bracketed paste feature of xterm?

Basically, when you paste text it is preceded by \e[200~ and terminated
with \e[201~. This has the potential to solve some irritations with
paste: undo can undo all the pasted text in one go, pasted tab
characters won't invoke completion and in vi command mode, pasted text
mightn't be treated as vi commands.

To handle this, what I've tried so far is putting \e[?2004h at the end
of PS1 and PS2 to enable it and \e[?2004l in POSTEDIT so it doesn't
remain enabled for other software. I then put together the following
zle widget which is, of course, bound to \e[200~.

bracketed-paste() { 
 local REPLY paste
 local end=$'\e[201~' idx=1
 while (( idx <= $#end )) && read -k 1; do
   [[ $REPLY = $end[idx++] ]] || (( idx = 1 + (#REPLY == #end) ))
 if (( NUMERIC )); then

The main problem I've found is that you can't paste into the mini-
buffer. Is there any way around that?

Does it make sense to include this function in Functions/Zle? It would
still require people to enable bracketed paste in their xterm. Any other
thoughts on what you might do with the pasted text besides pasting it.
$LASTWIDGET might be useful here. The function above quotes the text if
you supply a numeric argument. This can be useful when pasting, e.g.
URLs. In the past, I've used a separate widget that tries to get the
buffer with xclip, xselection or xprop.


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