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.

l0b0
  • 51,350

4 Answers4

8

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

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()
Thomas Dickey
  • 76,765
  • 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 07:29
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.

ssb
  • 21
-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.

slm
  • 369,824