From 1459a7651d27a43f9350cbc69dd9a01369c3e5d5 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 1 Oct 2017 19:15:07 +0300 Subject: path_add: prepend --- %HOME%/.bash_utils/path.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to '%HOME%/.bash_utils/path.sh') diff --git a/%HOME%/.bash_utils/path.sh b/%HOME%/.bash_utils/path.sh index 9a0e1a2..9f1fdd4 100644 --- a/%HOME%/.bash_utils/path.sh +++ b/%HOME%/.bash_utils/path.sh @@ -29,19 +29,20 @@ path_add() ( local -A dest_dict local -a dest_list + for path in ${src_list[@]+"${src_list[@]}"}; do + [ -n "${dest_dict[$path]+x}" ] && continue + dest_dict[$path]=1 + dest_list+=("$path") + done + if [ -n "${PATH-}" ]; then while IFS= read -d '' -r path; do + [ -n "${dest_dict[$path]+x}" ] && continue dest_dict[$path]=1 dest_list+=("$path") done < <( str_split -z -- "${PATH-}" ':' | xargs -0 -- readlink -z --canonicalize-missing -- ) fi - for path in ${src_list[@]+"${src_list[@]}"}; do - [ -n "${dest_dict[$path]+x}" ] && continue - dest_dict[$path]=1 - dest_list+=("$path") - done - str_join ':' ${dest_list[@]+"${dest_list[@]}"} ) -- cgit v1.2.3