Skip to content

Instantly share code, notes, and snippets.

@pjohansson
Last active September 26, 2021 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjohansson/7a86da349161595bd4c1fa77c11be38e to your computer and use it in GitHub Desktop.
Save pjohansson/7a86da349161595bd4c1fa77c11be38e to your computer and use it in GitHub Desktop.
GMXRC file for the Fish shell. Add to `$GROMACS/bin` directory and source to set path and variables.
##########################################################
# Utilitary functions
##########################################################
function __gmxrc_replace_in_path --description="remove all occurrences of a value from a path variable, then prepend a new value to it"
if test (count $argv) -lt 2
return
end
set -l variable_name $argv[1]
set -l new_value $argv[2]
# Only do this if the old variable exists
if test (count $argv) -ge 3
set -l old_value $argv[3]
__gmxrc_remove_value_from_variable $variable_name $old_value
end
set --global --export --path --prepend $variable_name $new_value
end
function __gmxrc_remove_value_from_variable --description="remove all occurrences of a value from a variable"
if test (count $argv) -lt 2
return
end
# Get the variable name and content separately:
# `variable` is a copy of the input variable which we will
# remove matches from. We then set the content of that to
# the `variable_name`.
set -l variable_name $argv[1]
set -l variable $$argv[1]
set -l remove_value $argv[2]
# Find all matches and save their indices in reverse order,
# then remove them afterwards (in that reverse order) to ensure
# that the indices are correct if multiple matches are found
set -l matched_indices
for i in (seq (count $variable))
if test $variable[$i] = $remove_value
set --prepend matched_indices $i
end
end
for i in $matched_indices
set --erase variable[$i]
end
set $variable_name $variable
end
##########################################################
# This is the real configuration part. Create and set
# variables for this distribution, then replace old
# values with our new ones in system PATH variables.
##########################################################
# Save old values of these variables, so that we can remove
# them from the relevant path variables before adding our
# new variables. This is to keep system variables clean.
set --local OLD_GMXLDLIB $GMXLDLIB
set --local OLD_GMXBIN $GMXBIN
set --local OLD_GMXMAN $GMXMAN
# Requires: Fish version 3.2 or newer for `status dirname`.
# Otherwise, uncomment the second line to use the `dirname` utility (must be installed).
set --local GMXPREFIX (realpath (status dirname)/..)
# set --local GMXPREFIX (realpath (dirname (status filename))/..)
set --global --export GMXBIN {$GMXPREFIX}/bin
set --global --export GMXLDLIB {$GMXPREFIX}/lib
set --global --export GMXMAN {$GMXPREFIX}/share/man
set --global --export GMXDATA {$GMXPREFIX}/share/gromacs
set --global --export GMXTOOLCHAINDIR {$GMXPREFIX}/share/cmake
set --global --export GROMACS_DIR {$GMXPREFIX}
__gmxrc_replace_in_path LD_LIBRARY_PATH $GMXLDLIB $OLD_GMXLDLIB
__gmxrc_replace_in_path PKG_CONFIG_PATH $GMXLDLIB/pkgconfig $OLD_GMXLDLIB/pkgconfig
__gmxrc_replace_in_path PATH $GMXBIN $OLD_GMXBIN
__gmxrc_replace_in_path MANPATH $GMXMAN $OLD_GMXMAN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment