5

Is there some way to search XTerm's console history interactively, like Ctrl+Shift+f in GNOME Terminal and Terminator?

I could run script in my .bashrc or possibly even patch XTerm, but it would be nice to know if there is already some shortcut or configuration setting to do this without heavily modifying my runtime environment.

A way to save the entire scrollback buffer in a single operation (that is, without copying every page of it with a mouse) would be an OK fallback.

  • I think GNU Screen can save the terminal history. I don't know if this is the kind of thing you have in mind. – Faheem Mitha Jan 15 '14 at 20:43
6

There's nothing built in, exactly, but there are two ways to get at the scrollback text.

You can configure the XTerm.vt100.on4Clicks and XTerm.vt100.on5Clicks resources (or from on1Clicks onwards, for that matter) to choose to copy the whole scrollback to the X11 PRIMARY selection. For example, to copy the whole scrollback on a quadruple click, put this line in your .Xresources:

XTerm.vt100.on4Clicks: all

You'll then have to arrange your own method for bringing up some way to search the content of the X selection, such as opening an editor or a pager with a window manager binding.

You can call the print-everything action to send the whole scrollback to a program determined by the XTerm.vt100.printerCommand resource. For example, to open the scrollback in less (running in a new xterm) when you press Ctrl+/, put these lines in your .Xresources:

XTerm.vt100.printerCommand: xterm -e sh -c 'less <&3' 3<&0
XTerm.vt100.translations: #override Ctrl ~Meta ~Shift <Key>slash: print-everything()
  • +1 onNClicks is great. – l0b0 Jan 16 '14 at 13:03
  • I already have a printerCommand to save the scrollback history as HTML, so I can't override that. – l0b0 Jan 16 '14 at 13:07
  • @l0b0 While you can only define a single printerCommand, you could define it to act differently based on modifiers, e.g. bind both Meta+M and Shift+Meta+M and make your script detect whether Shift is pressed (which should be ok unless your computer is slow and you release Shift very quickly). I can't think of a shell utility for that, you can call XKbGetState from a small C or Python wrapper. – Gilles Jan 16 '14 at 13:23
  • The less trick works great, but I do see some escape sequences on each line. With -R I see less, but still some. Can I get rid of this? Thanks. – lzap May 15 '14 at 18:17
  • God that -- adding less -r solves that problem. – lzap May 15 '14 at 18:18
0

It's trivial to copy and paste all or as much of the scrollback text as you want.

Scroll back to the beginning of the text you want to copy, left-click where you want the copy to start, scroll to the end of what you want to copy, right-click, then use middle-click to paste or use xclip (-selection primary -o) to feed it to stdout or divert it into a file.

0

Xterm does have a feature which addresses this, called dynamic abbreviation. Added in patch #188 (2004), it is optional and may not be compiled into your copy of xterm. The manual page says:

   dabbrev-expand()
           Expands  the  word  before cursor by searching in the preceding
           text on the screen and  in  the  scrollback  buffer  for  words
           starting  with  that  abbreviation.  Repeating dabbrev-expand()
           several times in sequence searches for an alternative expansion
           by looking farther back.  Lack of more matches is signaled by a
           beep().  Attempts to expand an empty word (i.e., when cursor is
           preceded  by  a  space)  yield successively all previous words.
           Consecutive identical expansions are ignored.  The word here is
           defined  as a sequence of non-whitespace characters.  This fea-
           ture partially emulates the behavior of "dynamic  abbreviation"
           expansion  in  Emacs  (bound there to M-/).  Here is a resource
           setting for xterm which will do the same thing:

               *VT100*translations:    #override \n\
                       Meta <KeyPress> /:dabbrev-expand()
  • It sounds like this finds only a single word from part of that word, so it doesn't show any context. – l0b0 Apr 21 '16 at 7:29
-1

I didn't see any way to search within XTerm's scrollback buffer to look for things. I think your only choices are to use something like tmux or screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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