summaryrefslogtreecommitdiff
path: root/share/spack/csh/pathadd.csh
blob: 1e0800c5f3f43e2ee846056d4aea2118b7f5a21a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
########################################################################
# Prepends directories to path, if they exist.
#      pathadd /path/to/dir            # add to PATH
# or   pathadd OTHERPATH /path/to/dir  # add to OTHERPATH
########################################################################
# If no variable name is supplied, just append to PATH
# otherwise append to that variable.
set _pa_varname = PATH;
set _pa_new_path = $_pa_args[1];
[ $#_pa_args -gt 1 ] && set _pa_varname = $_pa_args[1] && set _pa_new_path = $_pa_args[2];

# Check whether the variable is set yet.
set _pa_old_value = ""
eval set _pa_set = '$?'$_pa_varname
[ $_pa_set -eq 1 ] && eval set _pa_old_value='$'$_pa_varname;

# Do the actual prepending here, if it is a dir and not already in the path
if ( -d $_pa_new_path && \:$_pa_old_value\: !~ *\:$_pa_new_path\:* ) then
    [ -n "$_pa_old_value" ] && setenv $_pa_varname $_pa_new_path\:$_pa_old_value
    [ -z "$_pa_old_value" ] && setenv $_pa_varname $_pa_new_path
endif

unset _pa_args _pa_new_path _pa_old_value _pa_set _pa_varname