From 0e68f7ef5507bba674f45cc1c004e061101d2e32 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 22 May 2023 08:34:52 +0000 Subject: path.sh: don't canonicalize paths in path_add Resolving symlinks is actually bad; what if the user wants to add a symlinked directory? You better make sure you pass absolute paths now though. --- %HOME%/.bash_utils/path.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/%HOME%/.bash_utils/path.sh b/%HOME%/.bash_utils/path.sh index 0661710..58707f4 100644 --- a/%HOME%/.bash_utils/path.sh +++ b/%HOME%/.bash_utils/path.sh @@ -23,13 +23,7 @@ path_add() ( [ "$#" -eq 0 ] && return 0 - local -a src_list - local path - readlink -z --canonicalize-missing -- "$@" | while IFS= read -d '' -r path; do - src_list+=("$path") - done - for path; do if str_contains "$path" ':'; then echo "${FUNCNAME[0]}: mustn't contain colon (':') characters: $path" >&2 @@ -40,14 +34,14 @@ path_add() ( local -A uniq_paths local -a new_paths current_paths - for path in ${src_list[@]+"${src_list[@]}"}; do + for path; do [ -n "${uniq_paths[$path]+x}" ] && continue uniq_paths[$path]=1 new_paths+=("$path") done if [ -n "${PATH-}" ]; then - str_split -z -- "${PATH-}" ':' | xargs -0 -- readlink -z --canonicalize-missing -- | while IFS= read -d '' -r path; do + str_split -z -- "${PATH-}" ':' | while IFS= read -d '' -r path; do [ -n "${uniq_paths[$path]+x}" ] && continue uniq_paths[$path]=1 current_paths+=("$path") -- cgit v1.2.3