if status -i
   if [ -r /usr/init/fish_completion ]
      source /usr/init/fish_completion
   end

   # only redirect module from stderr to stdout in interactive mode
   # to avoid breaking non interactive session (scp, sftp, etc)
   function _moduleraw
      # use "| source -" rather than "eval" to be able
      # to redirect stderr after stdout being evaluated
      eval /usr/bin/tclsh /usr/lib/arm-linux-gnueabihf/modulecmd.tcl fish $argv | source -
   end
   function module
      _moduleraw $argv ^&1
   end
else
   function module
      eval /usr/bin/tclsh /usr/lib/arm-linux-gnueabihf/modulecmd.tcl fish $argv | source -
   end
end

# no switchml definition since there is no Fish support in C version

# setup ENV variables to get module defined in sub-shells (works for 'sh'
# and 'ksh' in interactive mode and 'sh' (zsh-compat), 'bash' and 'ksh'
# (zsh-compat) in non-interactive mode.
set -xg ENV /usr/init/profile.sh
set -xg BASH_ENV /usr/init/bash

set -xg MODULESHOME /usr

if not contains /usr/bin $PATH
   set -xg PATH /usr/bin $PATH
end

set manpath (manpath ^/dev/null)
if not string match -q '*:/usr/share/man:*' :$manpath:
   if [ -z $manpath ]
      set -xg MANPATH /usr/share/man
   else
      set -xg MANPATH /usr/share/man:$manpath
   end
end

if not set -q MODULEPATH
   if [ -r /usr/init/.modulespath ]
      set -xg MODULEPATH (sed -n 's/[ 	#].*$//; /./H; $ { x; s/^\n//; s/\n/:/g; p; }' \
         /usr/init/.modulespath)
   else
      set -xg MODULEPATH ''
   end
end

if not set -q LOADEDMODULES
   set -xg LOADEDMODULES ''
end

# load modulerc only if module environment is empty
if [ -r /usr/init/modulerc -a "$MODULEPATH" = '' \
   -a "$LOADEDMODULES" = '' ]
   module source /usr/init/modulerc
end
