aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%/.bash_utils/path.sh
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-11-07 04:52:38 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-11-07 04:52:38 +0300
commit5696bd8088b8e44a33237c94a0ce18ed0313693a (patch)
treed7eda3919fc287fe503ce3ff2f14e06e53e387fb /%HOME%/.bash_utils/path.sh
parentsums_update: bugfix (diff)
downloadlinux-home-5696bd8088b8e44a33237c94a0ce18ed0313693a.tar.gz
linux-home-5696bd8088b8e44a33237c94a0ce18ed0313693a.zip
bugfix & code style
Add missing '--'s, make arrays and nounset play well, etc.
Diffstat (limited to '%HOME%/.bash_utils/path.sh')
-rw-r--r--%HOME%/.bash_utils/path.sh32
1 files changed, 17 insertions, 15 deletions
diff --git a/%HOME%/.bash_utils/path.sh b/%HOME%/.bash_utils/path.sh
index 7982427..4aff550 100644
--- a/%HOME%/.bash_utils/path.sh
+++ b/%HOME%/.bash_utils/path.sh
@@ -12,12 +12,12 @@ add_missing_path() (
[ "$#" -eq 0 ] && return 0
- local -a new_paths
+ local -a new_list
local path
while IFS= read -d '' -r path; do
- new_paths+=("$path")
- done < <( readlink --zero --canonicalize-missing -- "$@" )
+ new_list+=("$path")
+ done < <( readlink -z --canonicalize-missing -- "$@" )
for path; do
if str_contains "$path" ':'; then
@@ -26,21 +26,23 @@ add_missing_path() (
fi
done
- local -A old_paths_dict
- local -a old_paths_list
+ local -A old_dict
+ local -a old_list
- while IFS= read -d '' -r path; do
- 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
- [ -n "${old_paths_dict[$path]+x}" ] && continue
- old_paths_dict[$path]=1
- old_paths_list+=("$path")
+ if [ -n "${PATH-}" ]; then
+ while IFS= read -d '' -r path; do
+ old_dict[$path]=1
+ old_list+=("$path")
+ done < <( str_split -z -- "${PATH-}" ':' | xargs -0 -- readlink -z --canonicalize-missing -- )
+ fi
+
+ for path in ${new_list[@]+"${new_list[@]}"}; do
+ [ -n "${old_dict[$path]+x}" ] && continue
+ old_dict[$path]=1
+ old_list+=("$path")
done
- str_join ':' ${old_paths_list[@]+"${old_paths_list[@]}"}
+ str_join ':' ${old_list[@]+"${old_list[@]}"}
)
add_path() {