bash_completion.in (modules-5.1.1.tar.bz2) | : | bash_completion.in (modules-5.2.0.tar.bz2) | ||
---|---|---|---|---|
# shellcheck shell=bash | ||||
# | # | |||
# Bash commandline completion | # Bash commandline completion | |||
# | # | |||
_module_comgen_words_and_files() { | _module_comgen_words_and_files() { | |||
local k=0 | local k=0 | |||
local setnospace=1 | local setnospace=1 | |||
# do not append space to word completed if it is a directory (ends with /) | # do not append space to word completed if it is a directory (ends with /) | |||
for val in $(compgen -W "$1" -- "$2"); do | for val in $(compgen -W "$1" -- "$2"); do | |||
if [ !$setnospace -a "${val: -1:1}" = '/' ]; then | if [ ! $setnospace ] && [ "${val: -1:1}" = '/' ]; then | |||
# Bash >=4.0 is required for compopt | # Bash >=4.0 is required for compopt | |||
type compopt &>/dev/null && compopt -o nospace | type compopt &>/dev/null && compopt -o nospace | |||
setnospace=0 | setnospace=0 | |||
fi | fi | |||
COMPREPLY[k++]="$val" | COMPREPLY[k++]="$val" | |||
done | done | |||
} | } | |||
_module_avail() { | _module_avail() { | |||
local cur="${1:-}" | local cur="${1:-}" | |||
# skip avail call if word currently being completed is an option keyword | # skip avail call if word currently being completed is an option keyword | |||
if [ -z "$cur" -o "${cur:0:1}" != '-' ]; then | if [ -z "$cur" ] || [ "${cur:0:1}" != '-' ]; then | |||
module avail --color=never -s -t -S --no-indepth -o '' $cur 2>&1 | module avail --color=never -s -t -S --no-indepth -o '' "$cur" 2>&1 | |||
fi | fi | |||
} | } | |||
_module_savelist() { | _module_savelist() { | |||
module savelist --color=never -s -t 2>&1 | sed ' | module savelist --color=never -s -t 2>&1 | sed ' | |||
/No named collection\.$/d; | /No named collection\.$/d; | |||
/Named collection list$/d; | /Named collection list$/d; | |||
/:$/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_not_yet_loaded() { | |||
_module_avail ${1:-} | sort | @SED_ERE@ "\%^(${LOADEDMODULES//:/|})$%d" | _module_avail "${1:-}" | sort | @SED_ERE@ "\%^(${LOADEDMODULES//:/|})$%d" | |||
} | } | |||
_module_long_arg_list() { | _module_long_arg_list() { | |||
local cur="$1" i | local cur="$1" i | |||
if [[ ${COMP_WORDS[COMP_CWORD-2]} == sw* ]] | if [[ ${COMP_WORDS[COMP_CWORD-2]} == sw* ]] | |||
then | then | |||
_module_comgen_words_and_files "$(_module_not_yet_loaded $cur)" "$cur" | _module_comgen_words_and_files "$(_module_not_yet_loaded "$cur")" "$cur" | |||
return | return | |||
fi | fi | |||
for ((i = COMP_CWORD - 1; i > 0; i--)) | for ((i = COMP_CWORD - 1; i > 0; i--)) | |||
do case ${COMP_WORDS[$i]} in | do case ${COMP_WORDS[$i]} in | |||
add|load) | add|load) | |||
_module_comgen_words_and_files "$(_module_not_yet_loaded $cur)" "$cu r" | _module_comgen_words_and_files "$(_module_not_yet_loaded "$cur")" "$ cur" | |||
break;; | break;; | |||
rm|del|remove|unload|switch|swap) | rm|del|remove|unload|switch|swap) | |||
COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") ) | COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") ) | |||
break;; | break;; | |||
esac | esac | |||
done | done | |||
} | } | |||
_module() { | _module() { | |||
local cur="$2" prev="$3" cmds opts | local cur="$2" prev="$3" cmds opts | |||
COMPREPLY=() | COMPREPLY=() | |||
case "$prev" in | case "$prev" in | |||
add|add-any|load|load-any|try-add|try-load) | add|add-any|load|load-any|try-add|try-load) | |||
_module_comgen_words_and_files "@comp_load_opts@ $(_module_n | _module_comgen_words_and_files "@comp_load_opts@ $(_module_n | |||
ot_yet_loaded $cur)" "$cur";; | ot_yet_loaded "$cur")" "$cur";; | |||
avail) _module_comgen_words_and_files "@comp_avail_opts@ $(_module_ | avail) _module_comgen_words_and_files "@comp_avail_opts@ $(_module_ | |||
avail $cur)" "$cur";; | avail "$cur")" "$cur";; | |||
edit) _module_comgen_words_and_files "$(_module_avail $cur)" "$cur | edit) _module_comgen_words_and_files "$(_module_avail "$cur")" "$c | |||
";; | ur";; | |||
aliases) COMPREPLY=( $(compgen -W "@comp_aliases_opts@" -- "$cur") );; | aliases) COMPREPLY=( $(compgen -W "@comp_aliases_opts@" -- "$cur") );; | |||
list|savelist) COMPREPLY=( $(compgen -W "@comp_list_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") );; | clear) COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );; | |||
restore|save|saveshow|saverm|is-saved) | restore|save|saveshow|saverm|is-saved) | |||
COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") ); ; | COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") ); ; | |||
rm|del|remove|unload) | rm|del|remove|unload) | |||
COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES //:/ }" -- "$cur") );; | COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES //:/ }" -- "$cur") );; | |||
switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES// :/ }" -- "$cur") );; | switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES// :/ }" -- "$cur") );; | |||
unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") ); ; | unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") ); ; | |||
use|-a|--append) ;; # let readline handle the completion | use|-a|--append) ;; # let readline handle the completion | |||
display|help|show|test|path|paths|is-loaded|info-loaded) | display|help|show|test|path|paths|is-loaded|info-loaded) | |||
_module_comgen_words_and_files "@comp_mfile_opts@ $(_module_ avail $cur)" "$cur";; | _module_comgen_words_and_files "@comp_mfile_opts@ $(_module_ avail "$cur")" "$cur";; | |||
is-avail) | is-avail) | |||
_module_comgen_words_and_files "@comp_isavail_opts@ $(_modul | _module_comgen_words_and_files "@comp_isavail_opts@ $(_modul | |||
e_avail $cur)" "$cur";; | e_avail "$cur")" "$cur";; | |||
lint) | ||||
_module_comgen_words_and_files "@comp_lint_opts@ $(_module_a | ||||
vail "$cur")" "$cur";; | ||||
mod-to-sh) | ||||
_module_comgen_words_and_files "@comp_modtosh_opts@ $(_modul | ||||
e_not_yet_loaded "$cur")" "$cur";; | ||||
whatis) | whatis) | |||
_module_comgen_words_and_files "@comp_whatis_opts@ $(_module _avail $cur)" "$cur";; | _module_comgen_words_and_files "@comp_whatis_opts@ $(_module _avail "$cur")" "$cur";; | |||
apropos|keyword|search) | apropos|keyword|search) | |||
COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );; | COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );; | |||
config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );; | config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );; | |||
-h|--help|-V|--version|purge|refresh|reload|sh-to-mod|source|state) | -h|--help|-V|--version|purge|refresh|reload|sh-to-mod|source|state|reset|sta sh|stashclear) | |||
;; | ;; | |||
append-path|prepend-path) | append-path|prepend-path) | |||
COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );; | COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );; | |||
remove-path) | remove-path) | |||
COMPREPLY=( $(compgen -W "@comp_rm_path_opts@" -- "$cur") ); ; | COMPREPLY=( $(compgen -W "@comp_rm_path_opts@" -- "$cur") ); ; | |||
initadd|initclear|initlist|initprepend|initrm) | initadd|initclear|initlist|initprepend|initrm) | |||
;; | ;; | |||
*) if test $COMP_CWORD -gt 2 | *) if test "$COMP_CWORD" -gt 2 | |||
then | then | |||
_module_long_arg_list "$cur" | _module_long_arg_list "$cur" | |||
else | else | |||
case "$cur" in | case "$cur" in | |||
# The mappings below are optional abbreviations for convenience | # The mappings below are optional abbreviations for convenience | |||
ls) COMPREPLY="list";; # map ls -> list | ls) COMPREPLY=( "list" );; # map ls -> list | |||
sw*) COMPREPLY="switch";; | sw*) COMPREPLY=( "switch" );; | |||
-*) COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") );; | -*) COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") );; | |||
*) COMPREPLY=( $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur" ) );; | *) COMPREPLY=( $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur" ) );; | |||
esac | esac | |||
fi;; | fi;; | |||
esac | esac | |||
} | } | |||
# define completion for ml command if command exists | # define completion for ml command if command exists | |||
if $(type -t ml >/dev/null); then | if $(type -t ml >/dev/null); then | |||
_ml() { | _ml() { | |||
local cur="$2" prev="$3" cmds opts | local cur="$2" prev="$3" cmds opts | |||
COMPREPLY=() | COMPREPLY=() | |||
case "$prev" in | case "$prev" in | |||
add|add-any|load|load-any|try-add|try-load) | add|add-any|load|load-any|try-add|try-load) | |||
_module_comgen_words_and_files "@comp_load_opts@ $(_modu | _module_comgen_words_and_files "@comp_load_opts@ $(_modu | |||
le_not_yet_loaded $cur)" "$cur";; | le_not_yet_loaded "$cur")" "$cur";; | |||
avail) _module_comgen_words_and_files "@comp_avail_opts@ $(_mod | avail) _module_comgen_words_and_files "@comp_avail_opts@ $(_mod | |||
ule_avail $cur)" "$cur";; | ule_avail "$cur")" "$cur";; | |||
edit) _module_comgen_words_and_files "$(_module_avail $cur)" " | edit) _module_comgen_words_and_files "$(_module_avail "$cur")" | |||
$cur";; | "$cur";; | |||
aliases) COMPREPLY=( $(compgen -W "@comp_aliases_opts@" -- "$cur") );; | aliases) COMPREPLY=( $(compgen -W "@comp_aliases_opts@" -- "$cur") );; | |||
list|savelist) COMPREPLY=( $(compgen -W "@comp_list_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") );; | clear) COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );; | |||
restore|save|saveshow|saverm|is-saved) | restore|save|saveshow|saverm|is-saved) | |||
COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur" ) );; | COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur" ) );; | |||
rm|del|remove|unload) | rm|del|remove|unload) | |||
COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMOD ULES//:/ }" -- "$cur") );; | COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMOD ULES//:/ }" -- "$cur") );; | |||
switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODUL ES//:/ }" -- "$cur") );; | switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODUL ES//:/ }" -- "$cur") );; | |||
unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur" ) );; | unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur" ) );; | |||
use|-a|--append) ;; # let readline handle the completion | use|-a|--append) ;; # let readline handle the completion | |||
display|help|show|test|path|paths|is-loaded|info-loaded) | display|help|show|test|path|paths|is-loaded|info-loaded) | |||
_module_comgen_words_and_files "@comp_mfile_opts@ $(_mod ule_avail $cur)" "$cur";; | _module_comgen_words_and_files "@comp_mfile_opts@ $(_mod ule_avail "$cur")" "$cur";; | |||
is-avail) | is-avail) | |||
_module_comgen_words_and_files "@comp_isavail_opts@ $(_m | _module_comgen_words_and_files "@comp_isavail_opts@ $(_m | |||
odule_avail $cur)" "$cur";; | odule_avail "$cur")" "$cur";; | |||
lint) | ||||
_module_comgen_words_and_files "@comp_lint_opts@ $(_modu | ||||
le_avail "$cur")" "$cur";; | ||||
mod-to-sh) | ||||
_module_comgen_words_and_files "@comp_modtosh_opts@ $(_m | ||||
odule_not_yet_loaded "$cur")" "$cur";; | ||||
whatis) | whatis) | |||
_module_comgen_words_and_files "@comp_whatis_opts@ $(_mo dule_avail $cur)" "$cur";; | _module_comgen_words_and_files "@comp_whatis_opts@ $(_mo dule_avail "$cur")" "$cur";; | |||
apropos|keyword|search) | apropos|keyword|search) | |||
COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );; | COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );; | |||
config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );; | config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );; | |||
-h|--help|-V|--version|purge|refresh|reload|sh-to-mod|source|state) | -h|--help|-V|--version|purge|refresh|reload|sh-to-mod|source|state|reset |stash|stashclear) | |||
;; | ;; | |||
append-path|prepend-path) | append-path|prepend-path) | |||
COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") ) ;; | COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") ) ;; | |||
remove-path) | remove-path) | |||
COMPREPLY=( $(compgen -W "@comp_rm_path_opts@" -- "$cur" ) );; | COMPREPLY=( $(compgen -W "@comp_rm_path_opts@" -- "$cur" ) );; | |||
initadd|initclear|initlist|initprepend|initrm) | initadd|initclear|initlist|initprepend|initrm) | |||
;; | ;; | |||
*) if test $COMP_CWORD -gt 2 | *) if test "$COMP_CWORD" -gt 2 | |||
then | then | |||
_module_long_arg_list "$cur" | _module_long_arg_list "$cur" | |||
else | else | |||
case "$cur" in | case "$cur" in | |||
# The mappings below are optional abbreviations for convenience | # The mappings below are optional abbreviations for convenience | |||
ls) COMPREPLY="list";; # map ls -> list | ls) COMPREPLY=( "list" );; # map ls -> list | |||
sw*) COMPREPLY="switch";; | sw*) COMPREPLY=( "switch" );; | |||
-*) COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") ) | -*) COMPREPLY=( $(compgen -W "@comp_opts@" -- "$cur") ) | |||
loaded_modules="" | loaded_modules="" | |||
for i in ${LOADEDMODULES//:/ }; do | for i in ${LOADEDMODULES//:/ }; do | |||
loaded_modules+="-${i} " | loaded_modules+="-${i} " | |||
done | done | |||
COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_o pts@ $loaded_modules" -- "$cur") );; | COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_o pts@ $loaded_modules" -- "$cur") );; | |||
*) _module_comgen_words_and_files "@comp_load_opts@ $(_mod ule_not_yet_loaded $cur)" "$cur" | *) _module_comgen_words_and_files "@comp_load_opts@ $(_mod ule_not_yet_loaded "$cur")" "$cur" | |||
COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") ) | COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") ) | |||
loaded_modules="" | loaded_modules="" | |||
for i in ${LOADEDMODULES//:/ }; do | for i in ${LOADEDMODULES//:/ }; do | |||
loaded_modules+="-${i} " | loaded_modules+="-${i} " | |||
done | done | |||
COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_o pts@ $loaded_modules" -- "$cur") );; | COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_o pts@ $loaded_modules" -- "$cur") );; | |||
esac | esac | |||
fi;; | fi;; | |||
esac | esac | |||
} | } | |||
End of changes. 24 change blocks. | ||||
35 lines changed or deleted | 64 lines changed or added |