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

Re: bracketed paste mode in xterm and urxvt



2015-06-03 17:31:31 +0200, Oliver Kiddle:
> [ moved to -workers ]
> 
> Yuri D'Elia wrote:
> > On 05/28/2015 10:30 PM, Daniel Hahler wrote:
> > > Apart from that I think that this (bracketed paste mode) should be
> > > included in Zsh's and get maintained this way.  Then it could also be
> > > adjusted for vi-mode.
> > 
> > I do agree that mainlining this would make a lot of sense, even as a
> > setopt. Or at least provide the keymap/functions needed to enable it.
> 
> I've been using bracketed paste for a while now and would also agree.
> The question is in what form to provide it? Note that I posted an
> alternative mechanism in workers/29898. The patch below is a port of
> that to C.
[...]

Also note that where terminals don't filter out control
characters, there's a potential problem in the way ^C is
handled.

zsh disables all signal keys but "intr". If the data to paste
(which is written in one go to the master side of the pty by
the terminal emulator) contains ^C, then a SIGINT will be sent
to zsh and the data from the start  of the paste up to ^C will
not be available for reading (discarded by the line discipline,
at least on Linux).

So any bracketed paste solution cannot be safe unless either ^C
is removed by the terminal emulator (like newer versions of
xterm), or ISIG is disabled in the terminal line-discipline.

So, for a truly safe paste, zsh should probably do the
equivalent of a stty -isig. That can only be done *before* the
paste, so that means isig must be turned off all the time (at
least when bracketed paste is enabled). Not desirable as CTRL-C
comes handy to stop lengthy processes by the shell.

To sum-up, for a safe bracketed paste, you need either:

- terminal emulator to filter out ^[ and ^C

Or if the terminal doesn't filter out ^[ and ^C both:

 - a different paste mode than xterm's \e[200~<to-paste>\e[201~ which
   doesn't work as <to-paste> may contain \e[201~ (something
   like: insert-formatted("\033[202~%S~%s",
   CLIPBOARD,PRIMARY,CUT_BUFFER0) would do).
 - zsh to disable isig.

Maybe a better approach would be to query the X selection for
instance with xclip/xsel where available. That can also be
integrated with the zsh kill ring. I once implemented a PoC
around that idea together with mouse integration

https://github.com/stephane-chazelas/misc-scripts/blob/master/mouse.zsh

-- 
Stephane



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