bash.d/00-path-helper

13 lines
449 B
Text
Raw Permalink Normal View History

# shellcheck shell=bash
# Helper functions to safely modify PATH
# Both check that the directory exists AND prevent duplicates on re-source
# Append directory to PATH (lower priority than existing entries)
path_append() {
[[ -d "$1" ]] && [[ ":$PATH:" != *":$1:"* ]] && PATH="$PATH:$1"
}
# Prepend directory to PATH (higher priority than existing entries)
path_prepend() {
[[ -d "$1" ]] && [[ ":$PATH:" != *":$1:"* ]] && PATH="$1:$PATH"
}