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:13:59 -0500
commit1ca87cb1ff6f9f73c009d92c83ffc89c336587cd (patch)
tree393d4fadb812b52a9e5c7d4710f448bb57b02ce0 /sh
parent270923bce074e9d6753eb26ade106c7fcb2e82ca (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/profile79
1 files changed, 32 insertions, 47 deletions
diff --git a/sh/profile b/sh/profile
index c9c2ca8..0979aa4 100644
--- a/sh/profile
+++ b/sh/profile
@@ -78,55 +78,40 @@ 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=""
+
+addtopath () {
+ 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
+}
# NEW PATH
-unset PATH
-if [ -d "$HOME/.local/bin/testing" ]; then
- PATH="$HOME/.local/bin/testing"
-fi
-if [ -d "$HOME/.local/bin/shortcmds" ]; then
- PATH="$PATH:$HOME/.local/bin/shortcmds"
-fi
-if [ -d "$HOME/.local/bin/generics" ]; then
- PATH="$PATH:$HOME/.local/bin/generics"
-fi
-if [ -d "$HOME/.local/bin/scripts" ]; then
- PATH="$PATH:$HOME/.local/bin/scripts"
-fi
-if [ -d "$HOME/.local/bin/sp" ]; then
- PATH="$PATH:$HOME/.local/bin/sp"
-fi
-if [ -d "$HOME/.local/bin/blocks" ]; then
- PATH="$PATH:$HOME/.local/bin/blocks"
-fi
-if [ -d "$HOME/.local/bin/ignore" ]; then
- PATH="$PATH:$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
- PATH="$PATH:$HOME/.local/bin"
-fi
-if [ -d "$HOME/.local/bin/flatpak-sc" ]; then
- PATH="$PATH:$HOME/.local/bin/flatpak-sc"
-fi
-if [ -d "$HOME/.local/bin/flatpak/exports/bin" ]; then
- PATH="$PATH:$HOME/.local/share/flatpak/exports/bin/"
-fi
-if [ -d "$CARGO_HOME/bin" ]; then
- PATH="$PATH:$CARGO_HOME/bin"
-fi
-if [ -d "$GOPATH/bin" ]; then
- PATH="$PATH:$GOPATH/bin"
-fi
-if [ -d "/var/lib/flatpak/exports/bin" ]; then
- PATH="$PATH:/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