Skip to content

Commit

Permalink
shell wrappers work when sourced from other dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
jooh committed Dec 20, 2019
1 parent f9bb8c0 commit 321a49f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion neuroconda.csh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ setenv PATH "/imaging/local/software/centos7/ants/bin/ants/bin:$PATH"
# isolate additions from this script so we can nuke them later
setenv NEUROCONDA_NEWPATH `echo "$PATH" | sed 's@'"$NEUROCONDA_OLDPATH"'@@g'`

# work out script directory
# (it's instructive to compare how ugly and slow this is compared to the bash solution)
set scriptdir = `lsof -w +p $$ | grep -oE /.\*neuroconda.csh | echo $script_path | xargs -0 dirname`
# work out what the conda version is
setenv NEUROCONDA_VERSION `cat neuroconda.yml | tr -s ' ' | grep -o 'name: .*' | cut -d ' ' -f 2`
setenv NEUROCONDA_VERSION `cat $scriptdir/neuroconda.yml | tr -s ' ' | grep -o 'name: .*' | cut -d ' ' -f 2`

conda activate "$NEUROCONDA_VERSION"
echo Welcome to "$NEUROCONDA_VERSION", running at "$CONDA_PREFIX"
4 changes: 3 additions & 1 deletion neuroconda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export PATH="/imaging/local/software/centos7/ants/bin/ants/bin/:$PATH"
# isolate additions from this script so we can nuke them later
export NEUROCONDA_NEWPATH=`echo "$PATH" | sed 's@'"$NEUROCONDA_OLDPATH"'@@g'`

# find script directory
scriptdir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")
# work out what the conda version is
export NEUROCONDA_VERSION=`cat neuroconda.yml | tr -s ' ' | grep -o 'name: .*' | cut -d ' ' -f 2`
export NEUROCONDA_VERSION=`cat $scriptdir/neuroconda.yml | tr -s ' ' | grep -o 'name: .*' | cut -d ' ' -f 2`

conda activate "$NEUROCONDA_VERSION"
echo Welcome to "$NEUROCONDA_VERSION", running at "$CONDA_PREFIX"

0 comments on commit 321a49f

Please sign in to comment.