Auto-completion of words from the terminal buffer

Short answer: No, not with classical shells like zsh or bash as typically your shell and terminal are different entities.

Long answer: Maybe. What typical happens is you enter a command and press Enter - now your shell forks and executes the specified command. Then the shell has no idea what is happening, the shell does not know what will be written to the terminal or what the executed program did, if it started other programs, wrote to your terminal or anything.

There are two possible solutions to your problem:

  1. Capture all the output from your executed commands and use it somehow for completion purpose (can be done but probably shouldn't be done)
  2. Use a different Terminal supporting 'completing' from your "shell buffer".

A solution for 2 is for example using emacs and multi-term and just using M-/ like you normal would to complete things from the terminal. Other terminals may offer a similar solution.

But do you really need this kind of completion? shell completion nowadays can complete man pages, commands, pids, sockets, command options, file paths from remote systems, and many more. This may be already sufficient for your use case or could be enhanced for your specific problem.


http://www.iterm2.com/#/section/features/autocomplete

iterm2 has exactly what you need. Bad thing it's for mac.

But since it's terminal you can ssh to linux/unix and it still works.