From 0fbde6c918e7203091375b4a07d66c78c77bac00 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 4 Nov 2016 02:40:53 +0300 Subject: add_missing_path: preserve order --- %HOME%/.bash_utils/path.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/%HOME%/.bash_utils/path.sh b/%HOME%/.bash_utils/path.sh index b9e78b6..7982427 100644 --- a/%HOME%/.bash_utils/path.sh +++ b/%HOME%/.bash_utils/path.sh @@ -26,17 +26,21 @@ add_missing_path() ( fi done - local -A old_paths + local -A old_paths_dict + local -a old_paths_list while IFS= read -d '' -r path; do - old_paths[$path]=1 - done < <( str_split -z -- "${PATH-}" ':' | xargs --null readlink --zero --canonicalize-missing -- ) + old_paths_dict[$path]=1 + old_paths_list+=("$path") + done < <( str_split -z -- "${PATH-}" ':' | xargs -0 readlink --zero --canonicalize-missing -- ) for path in ${new_paths[@]+"${new_paths[@]}"}; do - old_paths[$path]=1 + [ -n "${old_paths_dict[$path]+x}" ] && continue + old_paths_dict[$path]=1 + old_paths_list+=("$path") done - str_join ':' "${!old_paths[@]}" + str_join ':' ${old_paths_list[@]+"${old_paths_list[@]}"} ) add_path() { -- cgit v1.2.3