# -*- shell-script -*-
# This file defines a ksh alias.
# It also ends up in a zsh function directory
# so that zsh users can run this shell function with ksh scripts
if [ -n "${KSH_VERSION+x}" ]; then
  if [ "@silence_shell_debugging@" = "no" ]; then
     module()
     {
       eval "$($LMOD_CMD shell "$@")" && eval $(${LMOD_SETTARG_CMD:-:} -s sh)
     }
  else
     module()
     {
       ############################################################
       # Silence shell debug UNLESS $LMOD_SH_DBG_ON has a value
       if [ -z "${LMOD_SH_DBG_ON+x}" ]; then
          case "$-" in
            *v*x*) __lmod_sh_dbg='vx' ;;
            *v*)   __lmod_sh_dbg='v'  ;;
            *x*)   __lmod_sh_dbg='x'  ;;
          esac;
       fi
       
       if [ -n "${__lmod_sh_dbg:-}" ]; then
          set +$__lmod_sh_dbg 
          echo "Shell debugging temporarily silenced: export LMOD_SH_DBG_ON=1 for Lmod's output" 1>&2
       fi

       eval "$($LMOD_CMD shell "$@")" && eval $(${LMOD_SETTARG_CMD:-:} -s sh)
       __lmod_my_status=$?

       ############################################################
       # Un-silence shell debug after module command
       if [ -n "${__lmod_sh_dbg:-}" ]; then
         echo "Shell debugging restarted" 1>&2
         set -$__lmod_sh_dbg;
         unset __lmod_sh_dbg;
       fi;
       return $__lmod_my_status
     }
  fi
fi
