开发者

How to enable tab completion from the terminal specific to the executable

In bash, I believe it is possible to enable tab completion on the terminal for terms that are specific to the executable being invoked.

For example, given an executable "eat" with valid argume开发者_JS百科nts {cake, carrot, banana}, typing 'eat car' should complete to 'eat carrot'.

I believe this is possible because I have seen it with 'ant' tab-completing its targets (though how this was set up I don't know).

How can this behaviour be implemented?


This is done with scripts in /etc/bash_completion.d/ and if you want to write your own completion support for an executable, here's a tutorial to get you started.

If you only need to get the behaviour working for common executables, your Linux distro probably has a bash-completion package available with support for common commands.


This is quite similar to filename globbing where the shell will attempt to autocomplete based on the globbing wildcard...for instance....

echo foo*

will list all files in the current directory beginning with 'foo'...the bash shell globbed the wildcard and expanded it into a list of files...

MSDOS had a similar concept, although it was not explicitly linked in at run-time, I'm talking about the old Turbo C stuff, when the wildcard globbing was activated by linking with 'wildargs.obj' (if my memory serves me correct), internally, that code will iterate through the directory and expand the list based on wildcard pattern matching.

In Linux/*nix land, globbing is standard, but however, you cannot manually hit the sequence Tab key to do the pattern matching or completion...as different terminals may translate the tab key differently and of course handle it differently...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜