The Bash Argsparse Library 1.8
An high level argument parsing library for bash.
Loading...
Searching...
No Matches
Bash Completion-related functions.

argsparse-completion relies on a few shell settings: 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

argsparse-completion relies on a few shell settings:

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:250
Required configuration
shopt -s sourcepath

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

$ shopt sourcepath
sourcepath on
Limitations

Function Documentation

◆ __argsparse_compgen()

__argsparse_compgen ( param... )

A compgen wrapper.

This function will just call compgen with given argument, safely adding $cur in the command line. Also if compgen_prefix is set, a -P option will be provided to compgen.

Note
__argsparse_compgen() makes use of the bash-completion standard variables.
Parameters
param...any set of compgen options
Returns
compgen output and return code.

◆ __argsparse_complete()

__argsparse_complete ( )

Completion for the command stored in ${words[0]}.

Will load the script to complete, and invoke compgen according to context.

Return values
non-zeroif completed command cannot be sourced.

◆ __argsparse_complete_get_long()

__argsparse_complete_get_long ( word ,
long...  )

Find the option we want to complete.

If given word parameter is a recognized option, print the matching long option name. Also if "$cur" should be this option value, then return 0.

Parameters
wordany word.
long...a list of long options.
Returns
the long option matching given parameter.
Return values
0if given word matches an option and if that option accepts a value.

◆ __argsparse_complete_value()

__argsparse_complete_value ( option )

Complete the value an option.

Run compgen with values matching given option. If an array "option_<optionname>_values" exists, complete with its values. Else if option has a type, complete values according to type when possible. Else do nothing.

Note
__argsparse_complete_value() makes use of the bash-completion standard variables.
Parameters
optiona long option name.

◆ _argsparse_complete()

_argsparse_complete ( )

The argsparse completion function.

To enable completion on a script that uses the argsparse library, call the "complete" built-in as following:

Note
Technically, this function gets a parameter (the name of the command to complete), but it is ignored.