Skip to content

Latest commit

 

History

History
72 lines (52 loc) · 1.37 KB

File metadata and controls

72 lines (52 loc) · 1.37 KB

README

Demonstrate how to write autocomplete scripts

TODO:

  • register and unregister completions?
  • Do completions already exist for script?

Install completions

# source the completion script
. ./example-completion.bash  
# or
source ./example-completion.bash  

See basic options

# print options
./test-script.sh <tab> <tab>

See internals

# look at the internal variables that can be used to determine output
export COMPLETION_DEBUG="true"
./test-script.sh <tab> <tab>
unset COMPLETION_DEBUG

How it works

We assign a completion function and then use it to print out a list of options.

man builtins
/compgen

Examples

./test_script.sh --action=ls <tab>
./test_script.sh --action=ls -f=-l              
./test_script.sh --action=ls --flag=-la 

./test_script.sh --action=ps <tab>
./test_script.sh --action=ls --flag=-aux 

# gets completion options from the script
./test_script.sh --action=ls --flag=-la <tab>  

Remove completions

. ./remove-completions.bash    
# or
source ./remove-completions.bash    
./test-script.sh <tab> <tab>

Research