Hello Pierre,
The 'function-string' parameter of the set-function modulefile command
expects the function definition in the targeted shell language. If you
target sh shells, the conda function you describe could be set-up by the
following modulefile content:
#%Module
set-function conda {
if [ "$#" -lt 1 ]; then
$_CONDA_EXE
else
\local cmd="$1"
shift
case "$cmd" in
activate)
_conda_activate "$@"
;;
deactivate)
_conda_deactivate "$@"
;;
install|update|uninstall|remove)
$_CONDA_EXE "$cmd" "$@" && _conda_reactivate
;;
*)
$_CONDA_EXE "$cmd" "$@"
;;
esac
fi}
If you target multiple shells, you should define the function content for
each of them:
#%Module
# define function content depending on current shell family
switch -- [module-info shelltype] {
{sh} {
set condafunc {... sh function definition ...}
}
{fish} {
set condafunc {... fish function definition ...}
}
}
# define function if current shell supports shell function
if {[info exists condafunc]} {
set-function conda $condafunc
}
Cheers,
Xavier
Le ven. 14 déc. 2018 à 22:19, Pierre Girard <pie...@ge...> a
écrit :
> Hello,
>
> I’m trying to define a function in a module with the new
> set-function capability. All I can find in the documentation is this:
>
>
>
> *set-function* function-name function-string
>
> Creates a function with the name *function-name* in the user’s
> environment with the function body *function-string*. For some shells,
> functions are not possible and the command has no effect. When a
> *modulefile* is unloaded, *set-function* becomes *unset-function*.
>
>
>
>
>
> I don’t know which syntax I should use to write my function, should it be
> the target shell or some tcl? I was able to define a simple function that
> echos a message and another one that can call a program, but what I’m
> trying to write involves conditions and switch.
>
>
>
> Is it possible to write something like this (one of the many functions of
> the anaconda initialization script)?
>
>
>
> conda() {
>
> if [ "$#" -lt 1 ]; then
>
> $_CONDA_EXE
>
> else
>
> \local cmd="$1"
>
> shift
>
> case "$cmd" in
>
> activate)
>
> _conda_activate "$@"
>
> ;;
>
> deactivate)
>
> _conda_deactivate "$@"
>
> ;;
>
> install|update|uninstall|remove)
>
> $_CONDA_EXE "$cmd" "$@" && _conda_reactivate
>
> ;;
>
> *)
>
> $_CONDA_EXE "$cmd" "$@"
>
> ;;
>
> esac
>
> fi
>
> }
>
>
>
> Thanks for your help.
>
>
> _______________________________________________
> Modules-interest mailing list
> Mod...@li...
> https://lists.sourceforge.net/lists/listinfo/modules-interest
>
|