How to get real-time completion/suggestions in Linux terminal?
Solution 1
This Unix & Linux post describes what you want:
... I've come across a great, universal tool: command-line fuzzy finder.
It primarily allows you to “fuzzy-find” files (check the rich gif animation by the link above), but it also allows to feed arbitrary text data to it and filter this data. So, the shortcuts idea is simple: all we need is to maintain a file with paths (which are shortcuts), and fuzzy-filter this file. Here's how it looks: we type
cdg
command (from “cd global”, if you like), get a list of our bookmarks, pick the needed one in just a few keystrokes, and press Enter. Working directory is changed to the picked item:It is extremely fast and convenient: usually I just type 3-4 letters of the needed item, and all others are already filtered out.
It may not be what you're looking for, but the Vim editor with the CtrlP plugin can be used for this:
You'll need to install one of vim
, vim-nox
, vim-gnome
, vim-gtk
or vim-athena
for this to work. Installation instructions for CtrlP are provided in its website:
Clone the plugin into a separate directory:
$ cd ~/.vim $ git clone https://github.com/kien/ctrlp.vim.git bundle/ctrlp.vim
Add to your ~/.vimrc:
set runtimepath^=~/.vim/bundle/ctrlp.vim
Run at Vim's command line:
:helptags ~/.vim/bundle/ctrlp.vim/doc
- Restart Vim and check
:help ctrlp.txt
for usage instructions and configuration details.
If you have never used Vim before, it can be a bit intimidating. Run vimtutor
to get an idea of it.
Solution 2
You can write your own completion scripts for your shell.
For example, bash
uses simple shell scripts / functions for completion. Install bash-completions
if you haven't already and take a look at /usr/share/bash-completion/completions
for some examples.
In your script you could simply call locate
to get a list of matches and return them.
Related videos on Youtube
Comments
-
username123 over 1 year
I would like to have something similar to
everything
in windows (usinglocate
): every time I press a key, the file list that matches the current inputs gets updated immediately.I am wondering is that possible to do real-time text completion in terminal and how should I do that?
To make it more clear, suppose I have this function implemented as "foo", then when I type
foo a
and hitTAB
in the command line, it should give a list of all files with name containinga
, then if I continue to typeb
(now the command becomesfoo ab
), then the file list automatically (without need to hit anything else) gets updated to those containingab
, and so forth.-
username123 over 8 yearsHow to get real-time updates of the results?
-
username123 over 8 years@muru Thanks, but that is not what I am asking. I mean the results need to be updated every time I press down a new key.
-
muru over 8 yearsWhat are you trying to accomplish here? What's the intended use case?
-
username123 over 8 years@muru I added a description, if you could take a look.
-
0x2b3bfa0 over 8 yearsYou could try to use a shell called
fish
. It does some auto-completion magic, however it may be not what you want. -
username123 over 8 years@Helio Thanks, is it similar to
zsh
? -
0x2b3bfa0 over 8 years@username123: Yes, it's similar to
zsh
. However (as far as I know) it does some autocompletion on the user input. As I'm not a Windows user, I can't know if that is what you want. -
0x2b3bfa0 over 8 years@username123: Please check this asciinema recorded in
fish
by me: asciinema.org/a/det1crzgnph8m9fwklq50pwqq
-