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
|
#compdef module
# Main dispatcher
_module()
{
_arguments \
'(-h --help)'{--help,-h}'[display usage info]' \
'(- *)'{--version,--v}'[module command version]' \
'(-t --terse)'{--terse,-t}'[display avail, list and spider output in short format]' \
'(-d --default)'{--default,-d}'[List default modules only when used with avail]' \
'(-D --debug)'{--debug,-D}'[Send program tracing information to stderr]' \
'(-w --width)'{--width,-w}'[use given width for max term width]' \
'(-q --quiet)'{--quiet,-q}'[disable verbose messages]' \
'(-s --style)'{--style,-s}'[avail output style]' \
'--mt[display the module table]' \
'(-r --regexp)'{--regexp,-r}'[lua regular expression matching]' \
'--ignore_cache[Treat the cache file(s) as out-of-date]' \
'--mt[show module table]' \
'*::module command:_module_command'
}
_module_command()
{
local curcontext="$curcontext"
local -a _module_cmds
_module_cmds=(
"help:print the usage of each sub-command"
"load:load a module into the shell environment"
"try-load:load a module into the shell environment, no warnings if not found"
"add:load a module into the shell environment"
"unload:remove a module from the shell environment"
"rm:remove a module from the shell environment"
"swap:swap loaded a loaded module with another module"
"spider:List all possible modules"
"show:display information about a module"
"list:list loaded modules"
"avail:list all available modules"
"use:add a directory to MODULEPATH"
"unuse:remove a directory from MODULEPATH"
"update:reload all loaded modules"
"restore:load a module collection"
"purge:unload all loaded modules"
"refresh:refresh all non-persistent components of loaded modules"
"whatis:display module information"
"keyword:search for a given keyword in modules"
"mcc:module collection contents"
"collection:module collection contents"
"cc:module collection contents"
)
if (( CURRENT == 1 )); then
_describe -t commands 'module command' _module_cmds || compadd "$@"
else
local curcontext="$curcontext"
cmd="${${_module_cmds[(r)$words[1]:*]%%:*}}"
# Deal with any aliases
case $cmd in
add|try-load) cmd="load";;
rm) cmd="unload";;
display) cmd="show";;
esac
if (( $#cmd )); then
local update_policy
curcontext="${curcontext%:*:*}:module-${cmd}:"
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
_call_function ret _module_$cmd || _message 'no more arguments'
else
_message "unknown module command: $words[1]"
fi
return ret
fi
}
# Fills the available modules cache
_module_loaded_modules()
{
_loaded_modules=(${$(module -q -t list 2>&1 > /dev/null | sed ' /^ *$/d; /:$/d; s#/*$##g;')})
}
# Fills the available modules cache
_module_available_modules()
{
if [[ -n $MODULEPATH ]]; then
_available_modules=(${$(module -q -t avail 2>&1 > /dev/null | sed ' /:$/d; s#/*$##g;')})
fi
}
# Fills the available modules cache
_module_spider_list()
{
_spider_list=(${$(module -q -t spider 2>&1 > /dev/null)})
}
_module_restore()
{
_savelist_list=(${$(module -q -t savelist 2>&1 > /dev/null)})
compadd "$@" -a -- _savelist_list
}
_ml_mcc()
{
_savelist_list=(${$(module -q -t savelist 2>&1 > /dev/null)})
compadd "$@" -a -- _savelist_list
}
_ml_collection()
{
_savelist_list=(${$(module -q -t savelist 2>&1 > /dev/null)})
compadd "$@" -a -- _savelist_list
}
_ml_cc()
{
_savelist_list=(${$(module -q -t savelist 2>&1 > /dev/null)})
compadd "$@" -a -- _savelist_list
}
# Completion function for help
_module_help()
{
_module_available_modules
compadd "$@" -a -- _available_modules
}
# Completion function for load|add
_module_load()
{
_module_available_modules
compadd "$@" -a -- _available_modules
}
# Completion function for spider
_module_spider()
{
_module_spider_list
compadd "$@" -a -- _spider_list
}
# Completion function for unload|rm
_module_unload()
{
_module_loaded_modules
compadd "$@" -a -- _loaded_modules
}
# Completion function for switch|swap
_module_swap()
{
# Actually first argument could be a loaded module
if (( CURRENT == 2 )); then
_module_loaded_modules
compadd "$@" -a -- _loaded_modules
else
_module_available_modules
compadd "$@" -a -- _available_modules
fi
}
# Completion function for display|show
_module_show()
{
_module_available_modules
compadd "$@" -a -- _available_modules
}
# Completion function for avail
### No completion (yet?)
# Completion function for use
_module_use()
{
_arguments -s \
'(-a --append)'{--append,-a}'[append the directories instead of prepending]' \
'*:directory:_files -/'
}
# Completion function for unuse
_module_unuse()
{
compadd "$@" -- ${=MODULEPATH//:/ }
}
# Completion function for whatis
_module_whatis()
{
_module_available_modules
compadd "$@" -a -- _available_modules
}
_module "$@"
# Local Variables:
# mode: shell-script
# indent-tabs-mode: nil
# End:
|