From 3a21f592504009226421f28245ae9be4b7ba0978 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Fri, 24 Nov 2023 19:12:51 +0100 Subject: fix path control --- bash/10-env.profile | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bash/10-env.profile b/bash/10-env.profile index 10a1b59..a3decae 100644 --- a/bash/10-env.profile +++ b/bash/10-env.profile @@ -1,9 +1,19 @@ # vi:filetype=sh +function is_not_in_path() { + local regex="(:|^)${1//'/'/'\/*'}(:|$)" + [[ ! ${PATH} =~ $regex ]] +} + function appendpath() { - local regex="[:^]${1//'/'/'\/'}[:$]" - if [[ ! ${PATH} =~ $regex ]]; then - PATH=$PATH:$1 + if is_not_in_path "$1"; then + PATH="$PATH:$1" + fi +} + +function prependpath() { + if is_not_in_path "$1"; then + PATH="$1:$PATH" fi } @@ -12,10 +22,9 @@ appendpath "$DOTFILEBASE/scripts" appendpath "$HOME/.local/bin" appendpath "$HOME/go/bin" appendpath "$HOME/.cabal/bin" -appendpath "$HOME/.ghcup/bin" +prependpath "$HOME/.ghcup/bin" export PATH -unset appendpath if which nvim > /dev/null 2>&1 && [ ! "$FORCE_VANILLA_VIM" = "yes" ] ; then export EDITOR=nvim -- cgit v1.2.3