You are not logged in.

#1 2010-04-18 09:34:08

rwd
Member
Registered: 2009-02-08
Posts: 664

terminal annoyance: pasting newlines

Sometimes I paste a line into a terminal that I want to edit before executing, but because of a newline at the end it gets executed right away. Is there a way to prevent this?

Offline

#2 2010-04-18 10:45:50

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: terminal annoyance: pasting newlines

Try one of these in .xbindkeysrc

"xsel | tr -d '\n' | xsel -i; xdotool click --clearmodifiers 2"
    Control + Insert
"xdotool type --clearmodifiers "$(xsel | tr -d '\n')""
    Control + Insert

I do not recommend xdotool "key Shift+Insert" instead of "click 2", because the shift can be sticky which could mess up your entire system (I had to restart X, because it made every modifier sticky)

You can also bind to Shift + Insert. (EDIT: but note that you bound it to middle click, so e.g. in a GTK app it will paste in the wrong location)

The second one is non-destructive but won't work with unicode.

Last edited by Procyon (2010-04-18 10:50:33)

Offline

#3 2010-04-18 11:05:17

Kooothor
Member
From: Paname
Registered: 2008-08-02
Posts: 228

Re: terminal annoyance: pasting newlines

Or you can also, when you copy, be careful not to take the end character of the line.


ktr

Offline

#4 2010-04-18 12:04:05

Bralkein
Member
Registered: 2004-10-26
Posts: 354

Re: terminal annoyance: pasting newlines

Or if you type a # before pasting a single line then it will be taken as a comment if you accidentally paste the newline.

Offline

#5 2010-04-18 12:17:58

rwd
Member
Registered: 2009-02-08
Posts: 664

Re: terminal annoyance: pasting newlines

Procyon wrote:

Try one of these in .xbindkeysrc

"xsel | tr -d '\n' | xsel -i; xdotool click --clearmodifiers 2"
    Control + Insert
"xdotool type --clearmodifiers "$(xsel | tr -d '\n')""
    Control + Insert

I do not recommend xdotool "key Shift+Insert" instead of "click 2", because the shift can be sticky which could mess up your entire system (I had to restart X, because it made every modifier sticky)

You can also bind to Shift + Insert. (EDIT: but note that you bound it to middle click, so e.g. in a GTK app it will paste in the wrong location)

The second one is non-destructive but won't work with unicode.

Thanks.. that looks like the best solution so far.

Offline

#6 2010-04-18 12:19:42

kazuo
Member
From: São Paulo/Brazil
Registered: 2008-03-18
Posts: 413
Website

Re: terminal annoyance: pasting newlines

With you use urxvt you can edit the source code to remove pasted newlines

--- a/rxvt-unicode-9.07/src/screen.C  2009-12-29 02:16:18.000000000 -0200
+++ b/rxvt-unicode-9.07/src/screen.C       2010-04-18 09:13:11.853162361 -0300
@@ -2676,7 +2676,7 @@
   /* convert normal newline chars into common keyboard Return key sequence */
   for (unsigned int i = 0; i < len; i++)
     if (data[i] == C0_LF)
-      data[i] = C0_CR;
+      data[i] = ' ';
 
   if (priv_modes & PrivMode_BracketPaste)
     tt_printf ("\e[200~");

I think this can be done with the perl interface of urxvt, so you can have more power (yes, you can set urxvt to call perl commands on key-press) I'm working on this but I cannot found a clean way to get the content of primary clipboard buffer, (only from the internel urxvt buffer via $self->selection, I can cal xsel but this is ugly)

Offline

Board footer

Powered by FluxBB