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.

Imagine I have a bash session in a terminal, just after some output:

$ grep foo *.txt
this.txt: something123 foo
$

After this grep, let's say that my next command will take something123 as an argument.

Are there any tools that will allow me to tab/auto-complete the something123 at the prompt? i.e. autocomplete reading from the recent terminal buffer?

Specifically: I want to be able to type grep at the prompt, a few characters of something123 and the rest of something123 appear, just as it would if e.g. something123 were a name of a file in the current working directory.

Edit: I am currently using xfce4's terminal (on Arch Linux), but am open to others!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You could do this with a custom script but as far as I know this is not builtin behavior on any system -- certainly not with tab completion.

See http://tldp.org/LDP/abs/html/tabexpansion.html for instructions on how to code up something like this yourself. Warning: detailed knowledge of bash commands required if you decide to take up the task of writing this yourself, but given that you just want to do a certain grep, I don't think it'd be all that difficult.

share|improve this answer
    
Thanks for that pointer. A tempting side-project... I suppose some terminals would make their current scrollback buffer available programmatically (but not others.) –  wodow Jul 11 '12 at 18:36

You don't say what system you're using...

iTerm2 on Mac OS X will do this, using the Cmd+; keyboard shortcut. It's not quite like tab completion (you have to select from the terminal's GUI completion list before it sends any keypresses to the underlying process), but it saves you keystrokes nonetheless. See http://www.iterm2.com/#/section/features/autocomplete.

I'd be surprised if there weren't something similar for Unix.

This sort of behaviour would actually be easiest to implement directly on Windows (a process with a console can get access to its own scrollback buffer), but despite that I've never seen it done.

share|improve this answer
    
Thanks for the answer! Yes, I should have been clearer with the platform - added now as xfce4's terminal on Arch Linux. –  wodow Jul 11 '12 at 18:33
    
I will take a look at iTerm2 equivalents. –  wodow Jul 11 '12 at 18:33

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.