I would find it very convenient if it would be possible to auto-complete using words from what I just seen on screen in terminal with TAB. Preferably in zsh. Is there any way to manage it?


$ git log


$ <prefix> <TAB> // now cycle through whatever from git log output matches my prefix

  • I like the idea, but the shell normally has no insight into what is being printed by other processes. Perhaps the terminal would be a better place to hook this in. I vaguely believe iTerm2 for macOS has something like what you propose.
    – tripleee
    Commented Apr 18, 2017 at 9:58
  • @tripleee I'm not an expert in linux, just occasionally using GNU tooling and git and lacking this feature. Any combination of shell/terminal will do. I didn't specify this should be done using shell only. I'm using iTerm2 on macOS from time to time. Theoretically I would hook up storing terminal output from terminal to someplace and then just parse stuff from this place in shell.
    – rotanov
    Commented Apr 18, 2017 at 10:04
  • 1
    Note that if you run M-x shell inside emacs you can use dabbrev-expand (M-/) to do this sort of expansion at the prompt, using any text in the buffer (or indeed other buffers). Of course, this is not a solution for non-emacs users, but perhaps others may know of editors that provide a similar feature.
    – meuh
    Commented Apr 18, 2017 at 12:50
  • 1
    See also: Quick way to open results from `find` or `locate` Commented Apr 18, 2017 at 13:36

1 Answer 1


If you are willing to use iTerm2 instead of whatever terminal you are currently using, it includes this feature. It requires macOS to run the terminal on, and for you to enable iTerm2 shell integration on the hosts(s) where you want this. (This basically adds some hooks for your shell to communicate with iTerm2.)

https://www.iterm2.com/features.html#autocomplete has a screen shot which shows the output of tail being presented as the top completion candidate for Command-;

The iTerm2 project is open source so I imagine the guts of this feature could be ripped out and included or reimplemented in other environments.

  • github.com/gnachman/iterm2-website/blob/master/source/… (the web site's source, not the iterm2 project proper) has the Bash code for this feature. There is another file in the same directory for zsh with similar functionality which however seems a lot simpler.
    – tripleee
    Commented Apr 18, 2017 at 11:48
  • Worked for me, which is great. It's not possible to autocomplete from less (or git log wrapped in less) output as it is now out of the box. I will look up in it, anyway it's not related to the question.
    – rotanov
    Commented Apr 19, 2017 at 4:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .