File: bash_completion.in

package info (click to toggle)
modules 5.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,036 kB
  • sloc: exp: 79,659; sh: 6,142; tcl: 5,900; makefile: 1,492; ansic: 474; python: 265; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (209 lines) | stat: -rw-r--r-- 9,731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# shellcheck shell=bash
#
# Bash commandline completion
#
_module_comgen_words_and_files() {
    local k=0
    local setnospace=1
    # do not append space to word completed if it is a directory (ends with /)
    for val in $(compgen -W "$1" -- "$2"); do
        if [ $setnospace -eq 1 ] && [ "${val: -1:1}" = '/' ]; then
            # Bash >=4.0 is required for compopt
            type compopt &>/dev/null && compopt -o nospace
            setnospace=0
        fi
        COMPREPLY[k++]="$val"
    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 'alias:indesym' "$cur" 2>&1
    fi
}

_module_spider() {
    local cur="${1:-}"
    # skip spider call if word currently being completed is an option keyword
    if [ -z "$cur" ] || [ "${cur:0:1}" != '-' ]; then
        module spider --color=never -s -t -S --no-indepth -o 'alias:indesym' "$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_ERE@ "\%^(${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)
            COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") )
            break;;
        esac
    done
}

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

    COMPREPLY=()

    case "$prev" in
    add|add-any|load|load-any|try-add|try-load)
                    _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur";;
    avail)          _module_comgen_words_and_files "@comp_avail_opts@ $(_module_avail "$cur")" "$cur";;
    spider)         _module_comgen_words_and_files "@comp_avail_opts@ $(_module_spider "$cur")" "$cur";;
    edit)           _module_comgen_words_and_files "$(_module_avail "$cur")" "$cur";;
    aliases)  COMPREPLY=( $(compgen -W "@comp_aliases_opts@" -- "$cur") );;
    list|savelist)  COMPREPLY=( $(compgen -W "@comp_list_opts@" -- "$cur") );;
    stashlist)  COMPREPLY=( $(compgen -W "@comp_stashlist_opts@" -- "$cur") );;
    stashpop|stashshow|stashrm)
                    COMPREPLY=( $(compgen -W "$(_module_stashlist)" -- "$cur") );;
    clear)  COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );;
    restore|save|saveshow|describe|saverm|disable|is-saved)
                    COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );;
    rm|del|remove|unload)
                    COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );;
    switch|swap)    COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );;
    unuse|is-used)  COMPREPLY=( $(IFS=: compgen -W "${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 "@comp_mfile_opts@ $(_module_avail "$cur")" "$cur";;
    is-avail)
                    _module_comgen_words_and_files "@comp_isavail_opts@ $(_module_avail "$cur")" "$cur";;
    lint)
                    _module_comgen_words_and_files "@comp_lint_opts@ $(_module_avail "$cur")" "$cur";;
    mod-to-sh)
                    _module_comgen_words_and_files "@comp_modtosh_opts@ $(_module_not_yet_loaded "$cur")" "$cur";;
    whatis)
                    _module_comgen_words_and_files "@comp_whatis_opts@ $(_module_avail "$cur")" "$cur";;
    apropos|keyword|search)
                    COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );;
    config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );;
    -h|--help|-V|--version|--dumpname|purge|refresh|reload|sh-to-mod|source|state|reset|stash|stashclear|cacheclear|update)
                    ;;
    append-path|prepend-path)
                    COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );;
    remove-path)
                    COMPREPLY=( $(compgen -W "@comp_rm_path_opts@" -- "$cur") );;
    initadd|initclear|initlist|initprepend|initrm)
                    ;;
    *)  if test "$COMP_CWORD" -gt 2
        then
            _module_long_arg_list "$cur"
        else
            case "$cur" in
            # The mappings below are optional abbreviations for convenience
            ls)     COMPREPLY=( "list" );;      # map ls -> list
            sw*)    COMPREPLY=( "switch" );;

            -*)     COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") );;
            *)      COMPREPLY=( $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") );;
            esac
        fi;;
    esac
}

# define completion for ml command if command exists
if type -t ml >/dev/null; then
    _ml() {
        local cur="$2" prev="$3"

        COMPREPLY=()

        case "$prev" in
        add|add-any|load|load-any|try-add|try-load)
                        _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur";;
        avail)          _module_comgen_words_and_files "@comp_avail_opts@ $(_module_avail "$cur")" "$cur";;
        spider)         _module_comgen_words_and_files "@comp_avail_opts@ $(_module_spider "$cur")" "$cur";;
        edit)           _module_comgen_words_and_files "$(_module_avail "$cur")" "$cur";;
        aliases)  COMPREPLY=( $(compgen -W "@comp_aliases_opts@" -- "$cur") );;
        list|savelist)  COMPREPLY=( $(compgen -W "@comp_list_opts@" -- "$cur") );;
        stashlist)  COMPREPLY=( $(compgen -W "@comp_stashlist_opts@" -- "$cur") );;
        stashpop|stashshow|stashrm)
                    COMPREPLY=( $(compgen -W "$(_module_stashlist)" -- "$cur") );;
        clear)  COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );;
        restore|save|saveshow|describe|saverm|disable|is-saved)
                        COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );;
        rm|del|remove|unload)
                        COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );;
        switch|swap)    COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );;
        unuse|is-used)  COMPREPLY=( $(IFS=: compgen -W "${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 "@comp_mfile_opts@ $(_module_avail "$cur")" "$cur";;
        is-avail)
                        _module_comgen_words_and_files "@comp_isavail_opts@ $(_module_avail "$cur")" "$cur";;
        lint)
                        _module_comgen_words_and_files "@comp_lint_opts@ $(_module_avail "$cur")" "$cur";;
        mod-to-sh)
                        _module_comgen_words_and_files "@comp_modtosh_opts@ $(_module_not_yet_loaded "$cur")" "$cur";;
        whatis)
                        _module_comgen_words_and_files "@comp_whatis_opts@ $(_module_avail "$cur")" "$cur";;
        apropos|keyword|search)
                        COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );;
        config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );;
        -h|--help|-V|--version|--dumpname|purge|refresh|reload|sh-to-mod|source|state|reset|stash|stashclear|cacheclear|update)
                        ;;
        append-path|prepend-path)
                        COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );;
        remove-path)
                        COMPREPLY=( $(compgen -W "@comp_rm_path_opts@" -- "$cur") );;
        initadd|initclear|initlist|initprepend|initrm)
                        ;;
        *)  if test "$COMP_CWORD" -gt 2
            then
                _module_long_arg_list "$cur"
            else
                case "$cur" in
                # The mappings below are optional abbreviations for convenience
                ls)     COMPREPLY=( "list" );;      # map ls -> list
                sw*)    COMPREPLY=( "switch" );;

                -*)     COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") )
                        loaded_modules=""
                        for i in ${LOADEDMODULES//:/ }; do
                            loaded_modules+="-${i} "
                        done
                        COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_opts@ $loaded_modules" -- "$cur") );;
                *)       _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur"
                        COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") )
                        loaded_modules=""
                        for i in ${LOADEDMODULES//:/ }; do
                            loaded_modules+="-${i} "
                        done
                        COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_opts@ $loaded_modules" -- "$cur") );;
                esac
            fi;;
        esac
    }
    complete -o default -F _ml ml
fi
complete -o default -F _module module