summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2024-06-04 22:13:59 -0500
committerzachir <zachir@librem.one>2024-06-04 22:28:28 -0500
commit43c7d3b7e65b5ec36a5fe02dcbd3f2694cadeb53 (patch)
tree2b28255cd69a89585eb85c9c454f24f6a5b24d37 /sh
parent17a1b35c31aa0035f5570312a469d080ff00aefe (diff)
Fix adding paths to sh profile
The previous method was clunky, redundant, and terrible; it is now better, and should not keep adding the same directories into the path when sourcing it over and over.
Diffstat (limited to 'sh')
-rw-r--r--sh/profile82
1 files changed, 29 insertions, 53 deletions
diff --git a/sh/profile b/sh/profile
index c37bc48..07f51f5 100644
--- a/sh/profile
+++ b/sh/profile
@@ -83,63 +83,39 @@ export BLENDER_3_0="/usr/bin/blender"
export SRCDIR="$HOME/.local/src"
# OLD PATH
-export SYSPATH="$PATH"
+export PATHS="$(echo "$PATH" | sed 's/:/\n/g')"
+USERPATH=""
-# NEW PATH
addtopath () {
- if [ -n "$PATH" ]; then
- PATH="$@:$PATH"
- else
- PATH="$@"
- fi
+ local USERPATHS="$(echo "$USERPATH" | sed 's/:/\n/g')"
+ if [ -d "$1" ]; then
+ echo "$PATHS" | /usr/bin/grep -qE "^$1$" && return
+ echo "$USERPATHS" | /usr/bin/grep -qE "^$1$" && return
+ [ -n "$USERPATH" ] && USERPATH="${USERPATH}:"
+ USERPATH="${USERPATH}$1"
+ fi
}
-unset PATH
-if [ -d "$HOME/.local/bin/testing" ]; then
- addtopath "$HOME/.local/bin/testing"
-fi
-if [ -d "$HOME/.local/bin/shortcmds" ]; then
- addtopath "$HOME/.local/bin/shortcmds"
-fi
-if [ -d "$HOME/.local/bin/generics" ]; then
- addtopath "$HOME/.local/bin/generics"
-fi
-if [ -d "$HOME/.local/bin/scripts" ]; then
- addtopath "$HOME/.local/bin/scripts"
-fi
-if [ -d "$HOME/.local/bin/sp" ]; then
- addtopath "$HOME/.local/bin/sp"
-fi
-if [ -d "$HOME/.local/bin/blocks" ]; then
- addtopath "$HOME/.local/bin/blocks"
-fi
-if [ -d "$HOME/.local/bin/ignore" ]; then
- addtopath "$HOME/.local/bin/ignore"
-fi
-if [ -d "$HOME/.local/bin/volsv" ]; then
- PATH="$PATH:$HOME/.local/bin/volsv"
-fi
-if [ -d "$HOME/.local/bin" ]; then
- addtopath "$HOME/.local/bin"
-fi
-if [ -d "$HOME/.local/bin/flatpak-sc" ]; then
- addtopath "$HOME/.local/bin/flatpak-sc"
-fi
-if [ -d "$HOME/.local/bin/flatpak/exports/bin" ]; then
- addtopath "$HOME/.local/share/flatpak/exports/bin/"
-fi
-if [ -d "$CARGO_HOME/bin" ]; then
- addtopath "$CARGO_HOME/bin"
-fi
-if [ -d "$GOPATH/bin" ]; then
- addtopath "$GOPATH/bin"
-fi
-if [ -d "/var/lib/flatpak/exports/bin" ]; then
- addtopath "/var/lib/flatpak/exports/bin"
-fi
+addtopath "$HOME/.local/bin/testing"
+addtopath "$HOME/.local/bin/shortcmds"
+addtopath "$HOME/.local/bin/generics"
+addtopath "$HOME/.local/bin/scripts"
+addtopath "$HOME/.local/bin/sp"
+addtopath "$HOME/.local/bin/blocks"
+addtopath "$HOME/.local/bin/ignore"
+addtopath "$HOME/.local/bin/volsv"
+addtopath "$HOME/.local/bin"
+addtopath "$HOME/.local/bin/flatpak-sc"
+addtopath "$HOME/.local/share/flatpak/exports/bin/"
+addtopath "$CARGO_HOME/bin"
+addtopath "$GOPATH/bin"
+addtopath "$ZVMPATH"
+addtopath "$ZVM_INSTALL"
+addtopath "/var/lib/flatpak/exports/bin"
# MERGE PATHS
-export PATH="$PATH:$SYSPATH"
+[ -n "$USERPATH" ] && export PATH="$USERPATH:$PATH"
-# CLEANUP
-unset SYSPATH
+unset -f addtopath
+unset USERPATH
+unset PATHS