Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
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 Apr 9 '13 at 1:19
add comment
up vote 0 down vote accepted

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!

share|improve this answer
    
wish the screenshot is not shrinked... –  LiuYan 刘研 Apr 9 '13 at 1:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.