public static final int
2
public static final int
3
public static final int
4
public static final int
1
public static final int
0
"\n# Define a completion specification (a compspec) for the\n# `%1$s`, `%1$s.sh`, and `%1$s.bash` commands.\n# Uses the bash `complete` builtin (see [6]) to specify that shell function\n# `_complete_%1$s` is responsible for generating possible completions for the\n# current word on the command line.\n# The `-o default` option means that if the function generated no matches, the\n# default Bash completions and the Readline default filename completions are performed.\ncomplete -F _complete_%1$s -o default %1$s %1$s.sh %1$s.bash\n"
"#!/usr/bin/env bash\n#\n# %1$s Bash Completion\n# =======================\n#\n# Bash completion support for the `%1$s` command,\n# generated by [picocli](https://picocli.info/) version %2$s.\n#\n# Installation\n# ------------\n#\n# 1. Source all completion scripts in your .bash_profile\n#\n# cd $YOUR_APP_HOME/bin\n# for f in $(find . -name \"*_completion\"); do line=\". $(pwd)/$f\"; grep \"$line\" ~/.bash_profile || echo \"$line\" >> ~/.bash_profile; done\n#\n# 2. Open a new bash console, and type `%1$s [TAB][TAB]`\n#\n# 1a. Alternatively, if you have [bash-completion](https://github.com/scop/bash-completion) installed:\n# Place this file in a `bash-completion.d` folder:\n#\n# * /etc/bash-completion.d\n# * /usr/local/etc/bash-completion.d\n# * ~/bash-completion.d\n#\n# Documentation\n# -------------\n# The script is called by bash whenever [TAB] or [TAB][TAB] is pressed after\n# \'%1$s (..)\'. By reading entered command line parameters,\n# it determines possible bash completions and writes them to the COMPREPLY variable.\n# Bash then completes the user input if only one entry is listed in the variable or\n# shows the options if more than one is listed in COMPREPLY.\n#\n# References\n# ----------\n# [1] http://stackoverflow.com/a/12495480/1440785\n# [2] http://tiswww.case.edu/php/chet/bash/FAQ\n# [3] https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html\n# [4] http://zsh.sourceforge.net/Doc/Release/Options.html#index-COMPLETE_005fALIASES\n# [5] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655\n# [6] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion\n# [7] https://stackoverflow.com/questions/3249432/can-a-bash-tab-completion-script-be-used-in-zsh/27853970#27853970\n#\n\nif [ -n \"$BASH_VERSION\" ]; then\n # Enable programmable completion facilities when using bash (see [3])\n shopt -s progcomp\nelif [ -n \"$ZSH_VERSION\" ]; then\n # Make alias a distinct command for completion purposes when using zsh (see [4])\n setopt COMPLETE_ALIASES\n alias compopt=complete\n\n # Enable bash completion in zsh (see [7])\n # Only initialize completions module once to avoid unregistering existing completions.\n if ! type compdef > /dev/null; then\n autoload -U +X compinit && compinit\n fi\n autoload -U +X bashcompinit && bashcompinit\nfi\n\n# CompWordsContainsArray takes an array and then checks\n# if all elements of this array are in the global COMP_WORDS array.\n#\n# Returns zero (no error) if all elements of the array are in the COMP_WORDS array,\n# otherwise returns 1 (error).\nfunction CompWordsContainsArray() {\n declare -a localArray\n localArray=(\"$@\")\n local findme\n for findme in \"${localArray[@]}\"; do\n if ElementNotInCompWords \"$findme\"; then return 1; fi\n done\n return 0\n}\nfunction ElementNotInCompWords() {\n local findme=\"$1\"\n local element\n for element in \"${COMP_WORDS[@]}\"; do\n if [[ \"$findme\" = \"$element\" ]]; then return 1; fi\n done\n return 0\n}\n\n# The `currentPositionalIndex` function calculates the index of the current positional parameter.\n#\n# currentPositionalIndex takes three parameters:\n# the command name,\n# a space-separated string with the names of options that take a parameter, and\n# a space-separated string with the names of boolean options (that don\'t take any params).\n# When done, this function echos the current positional index to std_out.\n#\n# Example usage:\n# local currIndex=$(currentPositionalIndex \"mysubcommand\" \"$ARG_OPTS\" \"$FLAG_OPTS\")\nfunction currentPositionalIndex() {\n local commandName=\"$1\"\n local optionsWithArgs=\"$2\"\n local booleanOptions=\"$3\"\n local previousWord\n local result=0\n\n for i in $(seq $((COMP_CWORD - 1)) -1 0); do\n previousWord=${COMP_WORDS[i]}\n if [ \"${previousWord}\" = \"$commandName\" ]; then\n break\n fi\n if [[ \"${optionsWithArgs}\" =~ ${previousWord} ]]; then\n ((result-=2)) # Arg option and its value not counted as positional param\n elif [[ \"${booleanOptions}\" =~ ${previousWord} ]]; then\n ((result-=1)) # Flag option itself not counted as positional param\n fi\n ((result++))\n done\n echo \"$result\"\n}\n\n# compReplyArray generates a list of completion suggestions based on an array, ensuring all values are properly escaped.\n#\n# compReplyArray takes a single parameter: the array of options to be displayed\n#\n# The output is echoed to std_out, one option per line.\n#\n# Example usage:\n# local options=(\"foo\", \"bar\", \"baz\")\n# local IFS=$\'\\n\'\n# COMPREPLY=($(compReplyArray \"${options[@]}\"))\nfunction compReplyArray() {\n declare -a options\n options=(\"$@\")\n local curr_word=${COMP_WORDS[COMP_CWORD]}\n local i\n local quoted\n local optionList=()\n\n for (( i=0; i<${#options[@]}; i++ )); do\n # Double escape, since we want escaped values, but compgen -W expands the argument\n printf -v quoted %%q \"${options[i]}\"\n quoted=\\\'${quoted//\\\'/\\\'\\\\\\\'\\\'}\\\'\n\n optionList[i]=$quoted\n done\n\n # We also have to add another round of escaping to $curr_word.\n curr_word=${curr_word//\\\\/\\\\\\\\}\n curr_word=${curr_word//\\\'/\\\\\\\'}\n\n # Actually generate completions.\n local IFS=$\'\\n\'\n echo -e \"$(compgen -W \"${optionList[*]}\" -- \"$curr_word\")\"\n}\n\n"