From e5f4c25593c13f19b2a9c07a3d2f4d49216f58e2 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Thu, 25 Feb 2021 19:39:59 +0100 Subject: [PATCH] bash: shorten PATH manipulation --- files/bashrc | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/files/bashrc b/files/bashrc index ac78560..64119e4 100644 --- a/files/bashrc +++ b/files/bashrc @@ -34,7 +34,7 @@ export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup.py" # shellcheck disable=SC1091 # /etc/profile is provided by macOS. [ "$(uname)" == "Darwin" ] && { PATH=""; source /etc/profile; } -_prepend_path() { # prepend $1 to variable $2 using : as separator +_prepend_path() { # prepend $1 to var $2 avoiding duplicates using : as separator if [ -d "$1" ] && [ -n "$2" ]; then local _path="${!2}" # get path variable value case ":$_path:" in @@ -46,26 +46,16 @@ _prepend_path() { # prepend $1 to variable $2 using : as separator } # Add custom bin dirs to PATH if they exist and are not already in PATH. -while read -r dir; do _prepend_path "$dir" PATH; done </dev/null 2>&1; then