aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%/.bash_utils/path.sh
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-04-02 08:18:01 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2022-04-02 13:39:59 +0300
commit42da15c1fbff60c4a49705b96ebb30721ccafb14 (patch)
tree3b86ccf4fd01e7224b5e401ba14cd49cee78ebae /%HOME%/.bash_utils/path.sh
parent.bash_utils: remove mysql.sh (diff)
downloadlinux-home-42da15c1fbff60c4a49705b96ebb30721ccafb14.tar.gz
linux-home-42da15c1fbff60c4a49705b96ebb30721ccafb14.zip
bash: best practices & linting
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_utils/path.sh20
1 files changed, 13 insertions, 7 deletions
diff --git a/%HOME%/.bash_utils/path.sh b/%HOME%/.bash_utils/path.sh
index c8c4613..326cbf7 100644
--- a/%HOME%/.bash_utils/path.sh
+++ b/%HOME%/.bash_utils/path.sh
@@ -11,15 +11,16 @@
path_add() (
set -o errexit -o nounset -o pipefail
+ shopt -s inherit_errexit lastpipe
[ "$#" -eq 0 ] && return 0
local -a src_list
- local path
- while IFS= read -d '' -r path; do
+ local path
+ readlink -z --canonicalize-missing -- "$@" | while IFS= read -d '' -r path; do
src_list+=("$path")
- done < <( readlink -z --canonicalize-missing -- "$@" )
+ done
for path; do
if str_contains "$path" ':'; then
@@ -38,11 +39,11 @@ path_add() (
done
if [ -n "${PATH-}" ]; then
- while IFS= read -d '' -r path; do
+ str_split -z -- "${PATH-}" ':' | xargs -0 -- readlink -z --canonicalize-missing -- | 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 -- )
+ done
fi
str_join ':' ${dest_list[@]+"${dest_list[@]}"}
@@ -50,7 +51,12 @@ path_add() (
path_export() {
local new_path
+ local ret
+
+ new_path="$( path_add "$@" )"
+ ret="$?"
+
+ [ "$ret" -ne 0 ] && return "$ret"
- new_path="$( path_add "$@" )" \
- && export PATH="$new_path"
+ export PATH="$new_path"
}