GitHub

API reference for bash.

Bash completion scripts (Effect's internal completions/bash). The script runs on Bash 3.2 and works without the bash-completion package.

Values

AttributeTypeDescription
INIT_COMPLETION_FALLBACKLiteral['if ! type _init_completion &>/dev/null; then\n _in…'] = 'if ! type _init_completion &>/dev/null; then\n _init_completion()\n {\n COMPREPLY=()\n local _i _j=0 _piece _line="$COMP_LINE"\n words=("${COMP_WORDS[0]}")\n cword=0\n _line="${_line#*"${COMP_WORDS[0]}"}"\n for ((_i = 1; _i < ${#COMP_WORDS[@]}; _i++)); do\n _piece="${COMP_WORDS[_i]}"\n if [[ "$_line" == [[:blank:]]* ]]; then\n ((_j++))\n words[_j]="$_piece"\n else\n words[_j]="${words[_j]}$_piece"\n fi\n ((_i == COMP_CWORD)) && cword=$_j\n _line="${_line#*"$_piece"}"\n done\n cur="${words[cword]}"\n prev=""\n ((cword > 0)) && prev="${words[cword-1]}"\n return 0\n }\nfi\n\n'
CHOICES_HELPER_NAMELiteral['_x--choices'] = '_x--choices'
CHOICES_HELPERLiteral['_x--choices()\n{\n local _cur="$1" _word="$2"; shif…'] = '_x--choices()\n{\n local _cur="$1" _word="$2"; shift 2\n\n local _head="${_cur%"$_word"}"\n local _open=""\n case "$_head" in\n *\\\') _open="\'" ;;\n *\\") _open=\'"\' ;;\n esac\n\n local _prefix="$_cur" _committed="$_head"\n _prefix=${_prefix//\\\\/}; _prefix=${_prefix//\\"/}; _prefix=${_prefix//\\\'/}\n _committed=${_committed//\\\\/}; _committed=${_committed//\\"/}; _committed=${_committed//\\\'/}\n\n COMPREPLY=()\n local _choice _rest _match\n for _choice in "$@"; do\n [[ "$_choice" == "$_prefix"* ]] || continue\n _rest="${_choice#"$_committed"}"\n case "$_open" in\n "\'")\n if [[ "$_head" == "\'" ]]; then\n _match=${_rest//\\\'/\\\'\\\\\\\'\\\'}\n else\n [[ "$_rest" == *\\\'* ]] && continue\n _match="$_rest"\n fi\n ;;\n \'"\')\n _match="${_rest//\\\\/\\\\\\\\}"\n _match="${_match//\\$/\\\\$}"\n _match="${_match//\\`/\\\\\\`}"\n _match="${_match//\\"/\\\\\\"}"\n ;;\n *)\n printf -v _match \'%q\' "$_rest"\n [[ -z "$_head" && "$_match" == \'~\'* ]] && _match="\\\\$_match"\n ;;\n esac\n [[ -n "$_open" && "$_match" == *"$_open" ]] && _match+="$_open"\n COMPREPLY+=("$_match")\n done\n}\n'
PATHS_HELPER_NAMELiteral['_x--paths'] = '_x--paths'
PATHS_HELPERLiteral['_x--paths()\n{\n local _kind="$1" _cur="$2" _word="…'] = '_x--paths()\n{\n local _kind="$1" _cur="$2" _word="$3"\n\n local _prefix="$_cur" _committed="${_cur%"$_word"}"\n _prefix=${_prefix//\\\\/}; _prefix=${_prefix//\\"/}; _prefix=${_prefix//\\\'/}\n _committed=${_committed//\\\\/}; _committed=${_committed//\\"/}; _committed=${_committed//\\\'/}\n\n local _typed="" _dir="$_committed" _open="" _i\n if [[ "$_word" == */* ]]; then\n _typed="${_word%/*}/"\n _dir="${_prefix%/*}/"\n if [[ "$_cur" == "$_word" ]]; then\n for ((_i = 0; _i < ${#_typed}; _i++)); do\n case "$_open${_typed:_i:1}" in\n \\\\|\\"\\\\) ((_i += 1)) ;;\n \\"|\\\') _open="${_typed:_i:1}" ;;\n \\"\\"|\\\'\\\') _open="" ;;\n esac\n done\n fi\n fi\n\n local _path _names=() _rest="${_word#"$_typed"}"\n while IFS= read -r _path; do\n if [[ "$_path" == "$_dir"* ]]; then\n _names+=("$_committed${_path#"$_dir"}")\n elif [[ -z "$_committed" ]]; then\n _names+=("$_path")\n _typed="" _rest="" _open=""\n fi\n done < <(compgen "$_kind" -- "$_prefix")\n if [[ -n "$_open" ]]; then\n _typed+="$_open"\n _rest="${_prefix##*/}"\n fi\n\n _x--choices "${_cur%"$_word"}$_rest" "$_rest" "${_names[@]}"\n for ((_i = 0; _i < ${#COMPREPLY[@]}; _i++)); do\n COMPREPLY[_i]="$_typed${COMPREPLY[_i]}"\n done\n}\n'

Functions

generate

generate(executable, descriptor) -> str
ParameterTypeDescription
executablestr
descriptorCommandDescriptor

Returns str

def generate(executable: str, descriptor: CommandDescriptor) -> str:
    safe = _sanitize(executable)
    helpers = _Helpers(f"_{safe}--choices", f"_{safe}--paths")
    name = _escape(executable)
    lines = [
        f"###-begin-{name}-completions-###",
        "#",
        "# Static completion script for Bash",
        "#",
        "# Installation:",
        f"#   {name} --completions bash >> ~/.bashrc",
        "#",
        "",
    ]
    lines += INIT_COMPLETION_FALLBACK.split("\n")[:-1]
    lines += CHOICES_HELPER.replace(CHOICES_HELPER_NAME, helpers.choices).split("\n")[:-1]
    lines.append("")
    paths = PATHS_HELPER.replace(PATHS_HELPER_NAME, helpers.paths)
    lines += paths.replace(CHOICES_HELPER_NAME, helpers.choices).split("\n")[:-1]
    lines.append("")
    _function(descriptor, [], lines, helpers)
    lines.append(f"complete -F _{safe} {name}")
    lines.append(f"###-end-{name}-completions-###")
    return "\n".join(lines)