Unix - Custom autocomplete functions
Jump to navigation
Jump to search
About
NOTE: This page is a daughter page of: Unix
Programmable completion is a powerful tool which allows you to type any string (say: "myprintprogram") and then if you hit [tab],[tab] (tab key twice) it will show you the options available (eg: "--printhtml --printtxt help").
Simle Completion Function in Bash
~/autocomplete_foo.sh:
#! /bin/csh
_foo()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "alpha beta bar baz" -- $cur) )
}
complete -F _foo foo
Now test by typing:
$ ~/autocomplete_foo.sh $ foo b[TAB][TAB] beta bar baz
Simle Completion Function in Zsh
Links
- Writing your own Bash Completion Function - great article