2009-12-08 19:45:35 +02:00
|
|
|
# Use of this file is deprecated, upstream completion is available in
|
|
|
|
# modules >= 3.2.7, use that instead.
|
|
|
|
#
|
2005-07-07 20:01:25 +00:00
|
|
|
# module completion by Ted Stern <stern@cray.com>
|
|
|
|
#
|
|
|
|
# Completion for Environment Modules `module' alias.
|
|
|
|
#
|
|
|
|
# See http://sourceforge.net/projects/modules/
|
|
|
|
# http://modules.sourceforge.net/
|
|
|
|
#
|
|
|
|
# There are several versions of modules that are commonly used. Older
|
|
|
|
# Cray UNICOS systems and many other sites use 2.2.2b. The latest GPL'd
|
|
|
|
# version is 3.1.6. But the module alias is somewhat self-documenting
|
|
|
|
# via the `module help' command, so use that to print the options.
|
|
|
|
#
|
|
|
|
# Programmable completion might be more difficult under tcsh since the
|
|
|
|
# module command is an alias, and the `module avail' command returns
|
|
|
|
# its output as stderr.
|
2009-01-14 22:24:51 +02:00
|
|
|
|
2009-07-29 00:22:14 +03:00
|
|
|
# Test for existence of /etc/profile.d/modules.sh too because we may end up
|
|
|
|
# being sourced before it and thus before the `module' alias has been defined.
|
2011-04-05 00:35:51 +03:00
|
|
|
[ -f /etc/profile.d/modules.sh ] || have module || return
|
2005-07-07 20:01:25 +00:00
|
|
|
|
|
|
|
_module_list ()
|
|
|
|
{
|
2009-12-09 22:46:09 +02:00
|
|
|
local modules="$( sed 's/:/ /g' <<<$LOADEDMODULES | sort )"
|
2009-10-19 21:24:25 +03:00
|
|
|
compgen -W "$modules" -- $1
|
2005-07-07 20:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_module_path ()
|
|
|
|
{
|
2009-12-09 22:46:09 +02:00
|
|
|
local modules="$( sed 's/:/ /g' <<<$MODULEPATH | sort )"
|
2009-10-19 21:24:25 +03:00
|
|
|
compgen -W "$modules" -- $1
|
2005-07-07 20:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_module_avail ()
|
|
|
|
{
|
2009-10-19 21:24:25 +03:00
|
|
|
local modules="$( \
|
|
|
|
module avail 2>&1 | \
|
2009-12-15 23:48:10 +02:00
|
|
|
command grep -E -v '^(-|$)' | \
|
2009-12-08 19:43:00 +02:00
|
|
|
xargs printf '%s\n' | sed -e 's/(default)//g' | sort )"
|
2005-07-07 20:01:25 +00:00
|
|
|
|
2009-10-19 21:24:25 +03:00
|
|
|
compgen -W "$modules" -- $1
|
2005-07-07 20:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# A completion function for the module alias
|
2009-10-19 21:24:25 +03:00
|
|
|
_module ()
|
|
|
|
{
|
2011-04-20 14:02:21 +03:00
|
|
|
local cur prev words cword
|
|
|
|
_init_completion || return
|
2005-07-07 20:01:25 +00:00
|
|
|
|
2011-04-20 14:02:21 +03:00
|
|
|
if [ $cword -eq 1 ] ; then
|
2009-10-19 21:24:25 +03:00
|
|
|
# First parameter on line -- we expect it to be a mode selection
|
2005-07-07 20:01:25 +00:00
|
|
|
|
2011-04-20 14:02:21 +03:00
|
|
|
local options
|
2009-12-15 23:48:10 +02:00
|
|
|
options="$( module help 2>&1 | command grep -E '^[[:space:]]*\+' | \
|
2009-10-19 21:24:25 +03:00
|
|
|
awk '{print $2}' | sed -e 's/|/ /g' | sort )"
|
2005-07-07 20:01:25 +00:00
|
|
|
|
2009-10-19 21:24:25 +03:00
|
|
|
COMPREPLY=( $(compgen -W "$options" -- "$cur") )
|
2005-07-07 20:01:25 +00:00
|
|
|
|
2011-04-20 14:02:21 +03:00
|
|
|
elif [ $cword -eq 2 ] ; then
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-11-22 11:43:26 +01:00
|
|
|
add|display|help|load|show|whatis)
|
2009-10-04 19:42:50 +02:00
|
|
|
COMPREPLY=( $(_module_avail "$cur") )
|
|
|
|
;;
|
2009-11-22 11:43:26 +01:00
|
|
|
rm|switch|swap|unload|update)
|
2009-10-04 19:42:50 +02:00
|
|
|
COMPREPLY=( $(_module_list "$cur") )
|
|
|
|
;;
|
|
|
|
unuse)
|
|
|
|
COMPREPLY=( $(_module_path "$cur") )
|
|
|
|
;;
|
|
|
|
esac
|
2011-04-20 14:02:21 +03:00
|
|
|
elif [ $cword -eq 3 ] ; then
|
|
|
|
case ${words[1]} in
|
2009-11-22 11:43:26 +01:00
|
|
|
swap|switch)
|
2009-10-04 19:42:50 +02:00
|
|
|
COMPREPLY=( $(_module_avail "$cur") )
|
|
|
|
;;
|
|
|
|
esac
|
2009-10-19 21:24:25 +03:00
|
|
|
fi
|
|
|
|
return 0
|
2011-04-04 22:14:39 +03:00
|
|
|
} &&
|
2009-10-22 12:04:29 +03:00
|
|
|
complete -F _module -o default module
|
2009-10-01 20:54:51 +03:00
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
2009-10-04 19:42:50 +02:00
|
|
|
# sh-basic-offset: 4
|
2009-10-01 20:54:51 +03:00
|
|
|
# sh-indent-comment: t
|
2009-10-04 19:42:50 +02:00
|
|
|
# indent-tabs-mode: nil
|
2009-10-01 20:54:51 +03:00
|
|
|
# End:
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|