tcsh autocompletion for modulefiles

279 Views Asked by At

I found this piece of code, which does auto-completion for module files in tcsh at https://opensource.apple.com/source/tcsh/tcsh-66/tcsh/complete.tcsh.

Could somebody help me understand how the 'alias Compl_module' works?

#from Dan Nicolaescu <[email protected]>
if ( $?MODULESHOME ) then
  alias Compl_module 'find ${MODULEPATH:as/:/ /} -name .version -o -name .modulea\* -prune -o -print  | sed `echo "-e s@${MODULEPATH:as%:%/\*@@g -e s@%}/\*@@g"`'
  complete module 'p%1%(add load unload switch display avail use unuse update purge list clear help initadd initrm initswitch initlist initclear)%' \
  'n%{unl*,sw*,inits*}%`echo "$LOADEDMODULES:as/:/ /"`%' \
  'n%{lo*,di*,he*,inita*,initr*}%`eval Compl_module`%' \
  'N%{sw*,initsw*}%`eval Compl_module`%' 'C%-%(-append)%' 'n%{use,unu*,av*}%d%' 'n%-append%d%' \
  'C%[^-]*%`eval Compl_module`%'
endif

Thanks a lot.

1

There are 1 best solutions below

1
On BEST ANSWER

Not sure this Compl_module alias is performing well as it tries to determine all existing modulefiles in modulepaths by just looking at existing files. Modulefiles can also be aliases, symbolic versions and virtual (in newer Modules versions >=4.1), so the Compl_module alias will miss that.

You will find a full completion script for the module command in the source repository of the Modules project.

This completion script calls module avail to correctly get all existing modulefiles in enabled modulepaths.

TCSH completion script is automatically enabled starting Modules version 4.0.