Skip to content

Module command extension in bashrc

fgeorgatos edited this page Aug 19, 2012 · 5 revisions

The following could allow you to have a more interesting experience with environment modules, place it in .bashrc:

# Supplied under an MIT/GPL context by [email protected]

export EBHOME="$HOME/easybuild"
export CFGS="$EBHOME/easybuild/easyconfigs"

export EBPATH=~/easybuild/easybuild/easyconfigs:~/.local/easybuild/ebfiles_repo/:~/arena/pkg2eb/outdir/:~/easybuild_build/ # adjust as needed

module() {
local x ## this would be needed to avoid the global-default attitude of bash variables

if [ "$1" = "search" ]
then
  if [ -z "$2" ]
   then
    echo "Not enough params passed for search"
    return
  else
    echo $EBPATH|tr : '\n'|xargs -n1 -I % find % -name '*.eb'|grep -i $2
    return
  fi
fi

if [ "$1" = "install" ]
then
  if [ -z "$2" ]
   then
    echo "Not enough params passed for install"
    return
  else
    shift
    ${EBHOME}/eb --robot ${CFGS} "$@"
    return
  fi
fi

x=`/usr/bin/modulecmd bash $*`;

# as suggest by Kenneth and seen at http://pastebin.com/D4ysF0hr on 20120819
if [ $? -eq 0 ]; then
    eval $x;
else
    echo "ERROR: module $* failed";
fi

}