Can gnome terminal be set up, to copy selection without prompt?

0

I often times want to copy a set of commands from terminal, that do not have an output; say a block like this:

prompt$ less file1.txt
prompt$ less file2.txt
prompt$ dhex file2.txt
prompt$ less file3.txt

Now, if I select this block of text with the mouse, and copy it with Ctrl-Shift-C; then when I paste in a text file, the prompt is there (as expected) - and then I have to waste time deleting the prompt :)

So I was wandering - is there a setting for gnome-terminal, such that when I do the same kind of copying, I end up with only the commands - without the prompt? This is what I want when I finally paste:

less file1.txt
less file2.txt
dhex file2.txt
less file3.txt

I'm interested in a solution that will allow me to get this in clipboard, with just mouse selection and Ctrl-Shift-C; I am aware I could do history X, but then I'd have to grep it - and think of a suitable grep expression (and the same problem is if I record a typescript of terminal session with script).

Any facilities that exist for that? If not for gnome-terminal, any other terminal that can be used under Gnome that offers such facility?

sdaau

Posted 2013-03-29T23:45:42.507

Reputation: 3 758

Answers

0

Well, I was quite bugged by this problem, so finally I coded a solution which comes very close: a filtering plugin for the Glipper clipboard manager, which allows for regex processing in filter functions, which can be applied to the clipboard contents upon a Copy action; released here:

... and here is a screenshot:

glipper-filter.png

However, since I want to use this only occasionally, toggling filtering may not be the best idea (since you have to toggle ON, copy/paste, and then toggle OFF) - so the plugin bypasses normal operation when a filter submenu entry is clicked, if Ctrl, Alt or c are held; so my "minimal" action to perform a one-off prompt filtering is like this:

  • Select a region of text (including prompts) in terminal
  • Press Ctrl+Alt+c (default shortcut) to bring up Glipper menu window
  • Keeping any (or all) of Ctrl, Alt or c held pressed,
    • hover over Filtering menu item
    • hover over and click desired filter (sub)menu item (e.g. TermCmdLog)
  • Glipper menu dissapears - held keys can now be released
  • Move pointer and click to focus text editor
  • Paste - the pasted contents are modified by the clicked filter (e.g. for TermCmdLog the input has prompts removed, and non-prompt lines commented)

In the end, I would still have preferred that the terminal itself has a keyboard chord for filtered output (say, press Ctrl+Shift+a, then release a, then while holding the others press c) - but then that would be OK for a single filter; and if you want to choose one from several filters at runtime, again there is the problem of having of yet another action to do a choice; and if it is solved via GUI window of menu entries - then this pluggin is just as good, I guess. Even better, it works for any GUI source of (copyable) text under Gnome desktop - not just for terminal.

Unfortunately, it's developed for Gnome/Gtk 2 / Python 2.7, so it's already deprecated; still, hope it can hope others (until I hear of a better solution - hopefully in this thread :)),
Cheers!

sdaau

Posted 2013-03-29T23:45:42.507

Reputation: 3 758

wish the screenshot is not shrinked... – LiuYan 刘研 – 2013-04-09T01:50:13.160

1

In Gnome Terminal, you can select a block of text using Mouse + CTRL key. This way you can copy all of the console output without the prompt. e.g:

enter image description here

Noam Manos

Posted 2013-03-29T23:45:42.507

Reputation: 771

1

Assuming you're using bash as your shell, you might just do something like:

history -a ; tail -5 $HISTFILE

replacing 5 with however many commands you want to go back. That should get you a clean listing that will copy/paste easily. Not exactly the kind of approach you seem to be fishing for, but it might suit.

Jason Sherman

Posted 2013-03-29T23:45:42.507

Reputation: 1 071

Many thanks for that, @JasonSherman - unfortunately, that only includes the terminal commands, not the output. I did come close in this answer, which I accepted (until I hear of anything better, at least). Cheers!

– sdaau – 2013-04-09T01:19:57.733

0

If you use, tmux terminal multiplexer, you can do this easily and much more!

Noam Manos already pointed out in the other answer Gnome Terminal does allow block copy with Ctrl + Mouse click and drag. I just wanted to point out another alternative which is more powerful. The tmux supports putting your terminal in "copy mode" and allows you to do block copy and much more -- It even supports multiple paste buffers that you can copy and use later.

I use following lines in my .tmux.conf file to use vi keybindings for block copy:

bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle 

It does take some effort to learn to setup and use tmux, but it is worth it and I am happy with it.

Thava

Posted 2013-03-29T23:45:42.507

Reputation: 101