4

I would like to have something similar to everything in windows (using locate): 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 hit TAB in the command line, it should give a list of all files with name containing a, then if I continue to type b (now the command becomes foo ab), then the file list automatically (without need to hit anything else) gets updated to those containing ab, and so forth.

closed as too broad by mikewhatever, David Foerster, hg8, user364819, Eric Carvalho Dec 18 '15 at 23:14

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • How to get real-time updates of the results? – username123 Dec 17 '15 at 0:04
  • @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. – username123 Dec 17 '15 at 0:06
  • What are you trying to accomplish here? What's the intended use case? – muru Dec 17 '15 at 0:07
  • @muru I added a description, if you could take a look. – username123 Dec 17 '15 at 0:09
  • 1
    You could try to use a shell called fish. It does some auto-completion magic, however it may be not what you want. – Helio Dec 17 '15 at 19:13
3

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:

cdg

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:

enter image description here enter image description here enter image description here

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:

  1. Clone the plugin into a separate directory:

    $ cd ~/.vim
    $ git clone https://github.com/kien/ctrlp.vim.git bundle/ctrlp.vim
    
  2. Add to your ~/.vimrc:

    set runtimepath^=~/.vim/bundle/ctrlp.vim
    
  3. Run at Vim's command line:

    :helptags ~/.vim/bundle/ctrlp.vim/doc
    
  4. 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.

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.