| 1 |
# sh/bash/zsh configuration file for Gromacs |
| 2 |
# First we remove old gromacs stuff from the paths |
| 3 |
# by selecting everything else. |
| 4 |
# This is not 100% necessary, but very useful when we |
| 5 |
# repeatedly switch between gmx versions in a shell. |
| 6 |
|
| 7 |
#we make use of IFS, which needs shwordsplit in zsh |
| 8 |
test -n "${ZSH_VERSION+set}" && setopt shwordsplit |
| 9 |
old_IFS="$IFS" |
| 10 |
IFS=":" |
| 11 |
|
| 12 |
replace_in_path() { |
| 13 |
# Parse PATH-like variable $1, and return a copy of it with any instances of $3 removed and $2 added to the beginning. |
| 14 |
# If $3 is empty, do not remove anything. |
| 15 |
local tmppath oldpath to_remove to_add old_shell_opts |
| 16 |
oldpath="$1" |
| 17 |
to_add="$2" |
| 18 |
to_remove="$3" |
| 19 |
if test -z "${oldpath}"; then |
| 20 |
echo "${to_add}" |
| 21 |
else |
| 22 |
if test "${oldpath}" = ":"; then |
| 23 |
echo "${to_add}:" |
| 24 |
else |
| 25 |
tmppath="${to_add}" |
| 26 |
old_shell_opts="$-" |
| 27 |
set -o noglob |
| 28 |
set -- ${oldpath}"" # Will put tokens to $@, including empty ones |
| 29 |
# If did not have noglob ("f") enabled before, disable it back |
| 30 |
if test -n "${old_shell_opts##*f*}"; then |
| 31 |
set +o noglob |
| 32 |
fi |
| 33 |
for i in "$@"; do |
| 34 |
if test \( -z "${to_remove}" \) -o \( "$i" != "${to_remove}" \); then |
| 35 |
tmppath="${tmppath}:${i}" |
| 36 |
fi |
| 37 |
done |
| 38 |
echo "${tmppath}" |
| 39 |
fi |
| 40 |
fi |
| 41 |
} |
| 42 |
|
| 43 |
# Keep current values to remove later |
| 44 |
OLD_GMXLDLIB="$GMXLDLIB" |
| 45 |
OLD_GMXBIN="$GMXBIN" |
| 46 |
OLD_GMXMAN="$GMXMAN" |
| 47 |
|
| 48 |
########################################################## |
| 49 |
# This is the real configuration part. We save the Gromacs |
| 50 |
# things in separate vars, so we can remove them later. |
| 51 |
# If you move gromacs, change the first line. |
| 52 |
########################################################## |
| 53 |
GMXPREFIX=@CMAKE_INSTALL_PREFIX@ |
| 54 |
GMXBIN=${GMXPREFIX}/@CMAKE_INSTALL_BINDIR@ |
| 55 |
GMXLDLIB=${GMXPREFIX}/@CMAKE_INSTALL_LIBDIR@ |
| 56 |
GMXMAN=${GMXPREFIX}/@CMAKE_INSTALL_MANDIR@ |
| 57 |
GMXDATA=${GMXPREFIX}/@GMX_INSTALL_GMXDATADIR@ |
| 58 |
GMXTOOLCHAINDIR=${GMXPREFIX}/@GMX_INSTALL_CMAKEDIR@ |
| 59 |
GROMACS_DIR=${GMXPREFIX} |
| 60 |
|
| 61 |
@LD_LIBRARY_PATH@=$(replace_in_path "${@LD_LIBRARY_PATH@}" "${GMXLDLIB}" "${OLD_GMXLDLIB}") |
| 62 |
PKG_CONFIG_PATH=$(replace_in_path "${PKG_CONFIG_PATH}" "${GMXLDLIB}/pkgconfig" "${OLD_GMXLDLIB}/pkgconfig") |
| 63 |
PATH=$(replace_in_path "${PATH}" "${GMXBIN}" "${OLD_GMXBIN}") |
| 64 |
# Ensure MANPATH always has a final : |
| 65 |
if test -z "$MANPATH" ; then |
| 66 |
MANPATH=":" |
| 67 |
fi |
| 68 |
MANPATH=$(replace_in_path "${MANPATH}" "${GMXMAN}" "${OLD_GMXMAN}") |
| 69 |
|
| 70 |
# export should be separate, so /bin/sh understands it |
| 71 |
export GMXBIN GMXLDLIB GMXMAN GMXDATA @LD_LIBRARY_PATH@ PATH MANPATH |
| 72 |
export PKG_CONFIG_PATH GROMACS_DIR |
| 73 |
|
| 74 |
IFS="$old_IFS" |
| 75 |
unset old_IFS |
| 76 |
|
| 77 |
# read bash completions if understand how to use them |
| 78 |
# and this shell supports extended globbing |
| 79 |
if test -n "${BASH_VERSION+set}" && (complete) > /dev/null 2>&1; then |
| 80 |
if (shopt -s extglob) > /dev/null 2>&1; then |
| 81 |
shopt -s extglob |
| 82 |
if [ -f $GMXBIN/gmx-completion.bash ]; then |
| 83 |
source $GMXBIN/gmx-completion.bash |
| 84 |
for cfile in $GMXBIN/gmx-completion-*.bash ; do |
| 85 |
source $cfile |
| 86 |
done |
| 87 |
fi |
| 88 |
fi |
| 89 |
elif test -n "${ZSH_VERSION+set}" > /dev/null 2>&1 ; then |
| 90 |
autoload compinit bashcompinit |
| 91 |
if (compinit) > /dev/null 2>&1; then |
| 92 |
compinit |
| 93 |
fi |
| 94 |
if (bashcompinit) > /dev/null 2>&1; then |
| 95 |
bashcompinit |
| 96 |
if [ -f $GMXBIN/gmx-completion.bash ]; then |
| 97 |
source $GMXBIN/gmx-completion.bash |
| 98 |
for cfile in $GMXBIN/gmx-completion-*.bash ; do |
| 99 |
source $cfile |
| 100 |
done |
| 101 |
fi |
| 102 |
fi |
| 103 |
fi |