0
  :   ˆl–Ðz¾”êj"Tâ€jàY¸ ©‹FÿÁ„!¿a–Ü4ý(&”ÔD¨ 	Å õÀ
àS�ÿÀ 3=    # shellcheck shell=bash
#
# Bash commandline completion
#
_module_comgen_words() {
    local -a words
    local val
    # split candidate list on IFS without triggering shell expansion (command
    # substitution, arithmetic, ...): candidate words may come from module
    # names read off disk, which must never be treated as executable code
    IFS=$' \t\n' read -r -d '' -a words <<<"$1"
    for val in "${words[@]}"; do
        case "$val" in
            "$2"*) COMPREPLY[${#COMPREPLY[@]}]="$val" ;;
        esac
    done
}

_module_comgen_words_and_files() {
    local start=${#COMPREPLY[@]} i
    _module_comgen_words "$1" "$2"
    # do not append space to word completed if it is a directory (ends with /)
    for ((i = start; i < ${#COMPREPLY[@]}; i++)); do
        if [ "${COMPREPLY[i]: -1:1}" = '/' ]; then
            # Bash >=4.0 is required for compopt
            type compopt &>/dev/null && compopt -o nospace
            break
        fi
    done
}

_module_avail() {
    local cur="${1:-}"
    # skip avail call if word currently being completed is an option keyword
    if [ -z "$cur" ] || [ "${cur:0:1}" != '-' ]; then
        module avail --color=never -s -t -S --no-indepth -o '' "$cur" 2>&1
    fi
}

_module_savelist() {
    module savelist --color=never -s -t 2>&1 | sed '
        /No named collection\.$/d;
        /Named collection list$/d;
        /:$/d;'
}

_module_stashlist() {
    module stashlist --color=never -s -t 2>&1 | sed '
        /No stash collection\.$/d;
        /Stash collection list$/d;
        /:$/d;'
}

_module_not_yet_loaded() {
    _module_avail "${1:-}" | sort | sed -E "\%^(${LOADEDMODULES//:/|})$%d"
}

_module_long_arg_list() {
    local cur="$1" i

    if [[ ${COMP_WORDS[COMP_CWORD-2]} == sw* ]]
    then
        _module_comgen_words_and_files "$(_module_not_yet_loaded "$cur")" "$cur"
        return
    fi
    for ((i = COMP_CWORD - 1; i > 0; i--))
        do case ${COMP_WORDS[$i]} in
        add|load)
            _module_comgen_words_and_files "$(_module_not_yet_loaded "$cur")" "$cur"
            break;;
        rm|del|remove|unload|switch|swap)
            _module_comgen_words "${LOADEDMODULES//:/ }" "$cur"
            break;;
        esac
    done
}

_module() {
    local cur="$2" prev="$3" cmds opts

    COMPREPLY=()

    case "$prev" in
    add|add-any|load|load-any|try-add|try-load)
                    _module_comgen_words_and_files "--auto --no-auto --force -f --icase -i --tag --tag= $(_module_not_yet_loaded "$cur")" "$cur";;
    avail)          _module_comgen_words_and_files "-a -C -d -i -j -L -l -o -S -t --all --contains --default --icase --json --latest --long --output --output= --starts-with --terse --indepth --no-indepth $(_module_avail "$cur")" "$cur";;
    edit)           _module_comgen_words_and_files "$(_module_avail "$cur")" "$cur";;
    aliases)  COMPREPLY=( $(compgen -W "-a --all" -- "$cur") );;
    list|savelist)  COMPREPLY=( $(compgen -W "-a -j -l -o -t --all --json --long --output --output= --terse" -- "$cur") );;
    stashlist)  COMPREPLY=( $(compgen -W "-j -l -t --json --long --terse" -- "$cur") );;
    stashpop|stashshow|stashrm)
                    _module_comgen_words "$(_module_stashlist)" "$cur";;
    clear)  COMPREPLY=( $(compgen -W "--force -f" -- "$cur") );;
    restore|save|saveshow|saverm|is-saved)
                    _module_comgen_words "$(_module_savelist)" "$cur";;
    rm|del|remove|unload)
                    _module_comgen_words "--auto --no-auto --force -f --icase -i ${LOADEDMODULES//:/ }" "$cur";;
    switch|swap)    _module_comgen_words "--auto --no-auto --force -f --icase -i --tag --tag= ${LOADEDMODULES//:/ }" "$cur";;
    unuse|is-used)  _module_comgen_words "${MODULEPATH//:/ }" "$cur";;
    use|-a|--append|cachebuild)   ;;               # let readline handle the completion
    display|help|show|test|path|paths|is-loaded|info-loaded)
                    _module_comgen_words_and_files "-i --icase $(_module_avail "$cur")" "$cur";;
    is-avail)
                    _module_comg