The Bash Argsparse Library 1.8
An high level argument parsing library for bash.
Loading...
Searching...
No Matches
argsparse-completion.sh File Reference

Bash completion for scripts using argsparse library. More...

Functions

 __argsparse_compgen (param...)
 A compgen wrapper.
 
 __argsparse_complete ()
 Completion for the command stored in ${words[0]}.
 
 __argsparse_complete_get_long (word, long...)
 Find the option we want to complete.
 
 __argsparse_complete_value (option)
 Complete the value an option.
 
 _argsparse_complete ()
 The argsparse completion function.
 

Detailed Description

Bash completion for scripts using argsparse library.

Author
Damien Nadé bash-.nosp@m.args.nosp@m.parse.nosp@m.@liv.nosp@m.na.or.nosp@m.g
Version
1.8
URL
https://github.com/Anvil/bash-argsparse
Purpose

To automatically enable, for bash-completion users, completion for scripts that use the argsparse library.

Usage

In your ~/.bashrc, add the following lines to enable completion for all your argsparse-written scripts:

. argsparse-completion.sh
complete -F _argsparse_complete [ your scripts names ... ]
_argsparse_complete()
The argsparse completion function.
Definition argsparse-completion.sh:248
Required configuration

argsparse-completion relies on a few shell settings:

  • "sourcepath" shell option must be enabled. This should be enabled by default, but you can enforce it by running:
shopt -s sourcepath

If correctly enabled, the following command below should return this output.

$ shopt sourcepath
sourcepath on
Limitations
  • Every time the completion is invoked, the completed script will be sourced, up to either the argsparse_parse_options() function call or any the first return top-level statement. This means that up to this point the script should not have any side effect (like file system alteration, network connections, ...), and should avoid time-consuming tasks up to this point.
  • Only a limited set of option types completion are currently implemented.