Skip to content

Commit

Permalink
init: update completion with stashlist output
Browse files Browse the repository at this point in the history
Update stashpop, stashrm and stashshow completion definition to use
stashlist output.
  • Loading branch information
xdelaruelle committed Oct 5, 2022
1 parent b2f5dbc commit c3d06a6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
15 changes: 13 additions & 2 deletions init/bash_completion.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ _module_savelist() {
/:$/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"
}
Expand Down Expand Up @@ -68,6 +75,8 @@ _module() {
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|saverm|is-saved)
COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );;
Expand All @@ -89,7 +98,7 @@ _module() {
apropos|keyword|search)
COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );;
config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );;
-h|--help|-V|--version|purge|refresh|reload|sh-to-mod|source|state|reset|stash|stashclear|stashpop|stashrm|stashshow)
-h|--help|-V|--version|purge|refresh|reload|sh-to-mod|source|state|reset|stash|stashclear)
;;
append-path|prepend-path)
COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );;
Expand Down Expand Up @@ -128,6 +137,8 @@ if $(type -t ml >/dev/null); then
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|saverm|is-saved)
COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );;
Expand All @@ -149,7 +160,7 @@ if $(type -t ml >/dev/null); then
apropos|keyword|search)
COMPREPLY=( $(compgen -W "@comp_search_opts@" -- "$cur") );;
config|--reset) COMPREPLY=( $(compgen -W "@comp_config_opts@" -- "$cur") );;
-h|--help|-V|--version|purge|refresh|reload|sh-to-mod|source|state|reset|stash|stashclear|stashpop|stashrm|stashshow)
-h|--help|-V|--version|purge|refresh|reload|sh-to-mod|source|state|reset|stash|stashclear)
;;
append-path|prepend-path)
COMPREPLY=( $(compgen -W "@comp_path_opts@" -- "$cur") );;
Expand Down
14 changes: 14 additions & 0 deletions init/fish_completion
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ function __fish_module_use_savelist --description 'Test if module command should
return 1
end

function __fish_module_use_stashlist --description 'Test if module command should have stash collections as potential completion'
for i in (commandline -opc)
if contains -- $i stashpop stashrm stashshow
return 0
end
end
return 1
end

function __fish_module_use_config --description 'Test if module command should have configuration parameters as potential completion'
for i in (commandline -opc)
if contains -- $i config
Expand All @@ -63,6 +72,11 @@ complete -c module -n '__fish_module_use_savelist' -f -a "(module savelist --col
/Named collection list\$/d; \
/:\$/d; \
/:ERROR:/d;')"
complete -c module -n '__fish_module_use_stashlist' -f -a "(module stashlist --color=never -s -t 2>&1 | sed '\
/No stash collection\.\$/d; \
/Stash collection list\$/d; \
/:\$/d; \
/:ERROR:/d;')"
complete -c module -n '__fish_module_use_config' -f -a "--dump-state --reset advanced_version_spec auto_handling avail_indepth avail_output avail_terse_output collection_pin_version collection_pin_tag collection_target color colors contact editor extended_default extra_siteconfig home icase implicit_default implicit_requirement list_output list_terse_output locked_configs mcookie_check mcookie_version_check ml nearly_forbidden_days pager protected_envvars quarantine_support rcfile redirect_output reset_target_state run_quarantine search_match set_shell_startup shells_with_ksh_fpath silent_shell_debug tag_abbrev tag_color_name tcl_linter term_background term_width unload_match_order variant_shortcut verbosity wa_277"

complete -f -n '__fish_module_no_subcommand' -c module -a 'help' --description 'Print this or modulefile(s) help info'
Expand Down
12 changes: 9 additions & 3 deletions init/tcsh_completion.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ alias _module_savelist '\\
/Named collection list$/d; \\
/:$/d; '"'"

alias _module_stashlist '\\
@TCLSH@ "@libexecdir@/modulecmd.tcl" tcsh stashlist --color=never -s -t |& sed '"'"'\\
/No stash collection\.$/d; \\
/Stash collection list$/d; \\
/:$/d; '"'"

alias _module_not_yet_loaded '\\
mkfifo /tmp/modules_tcsh_completion.$$.p1 /tmp/modules_tcsh_completion.$$.p2 && \\
( _module_avail | sort >! /tmp/modules_tcsh_completion.$$.p1 & ); \\
Expand Down Expand Up @@ -86,9 +92,9 @@ complete module 'n/help/`_module_avail`/' \
"n/stash/n/" \
"n/stashclear/n/" \
"n/stashlist/(@comp_stashlist_opts@)/" \
"n/stashpop/n/" \
"n/stashrm/n/" \
"n/stashshow/n/" \
'n/stashpop/`_module_stashlist`/' \
'n/stashrm/`_module_stashlist`/' \
'n/stashshow/`_module_stashlist`/' \
"n/--reset/(@comp_config_opts@)/" \
'n/-h/n/' \
'n/--help/n/' \
Expand Down
18 changes: 18 additions & 0 deletions init/zsh-functions/_module.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ _module_savelist() {
/:$/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"
}
Expand Down Expand Up @@ -48,6 +55,13 @@ _module_saved_colls() {
_describe -t saved-colls 'saved collections' saved_colls && ret=0
}

_module_stash_colls() {
local -a stash_colls;
stash_colls=(${$(_module_stashlist)})

_describe -t stash-colls 'stash collections' stash_colls && ret=0
}

_module_notloaded_mods() {
local -a not_yet_loaded_mods;
local suffix=' ';
Expand Down Expand Up @@ -230,6 +244,10 @@ _module() {
'(-t --terse)'{-t,--terse}'[Display output in terse format]' \
'(-j --json)'{-j,--json}'[Display output in JSON format]' && ret=0
;;
(stashpop|stashshow|stashrm)
_alternative 'avail-stashs:collections:{_module_stash_colls}' \
&& ret=0
;;
(clear)
_arguments \
'(-f --force)'{-f,--force}'[Skip confirmation dialog]' && ret=0
Expand Down

0 comments on commit c3d06a6

Please sign in to comment.