From 3d0b16d4cac0f415ef47edf098e42e49db093223 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 20 Nov 2016 23:30:27 +0300 Subject: refactoring --- %HOME%/.bash_utils/distr.sh | 8 +++----- %HOME%/.bash_utils/path.sh | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) (limited to '%HOME%') diff --git a/%HOME%/.bash_utils/distr.sh b/%HOME%/.bash_utils/distr.sh index e83cb88..fc77d9e 100644 --- a/%HOME%/.bash_utils/distr.sh +++ b/%HOME%/.bash_utils/distr.sh @@ -56,10 +56,8 @@ sums_update() ( existing[$path]=1 done < <( sums_list_paths -z ) - for path in "$@"; do - if [ -z "${existing[$path]+x}" ]; then - missing+=("$path") - fi + for path; do + [ -z "${existing[$path]+x}" ] && missing+=("$path") done [ "${#missing[@]}" -eq 0 ] && return 0 @@ -75,7 +73,7 @@ sums_update_distr() ( while IFS= read -d '' -r path; do paths+=("$path") - done < <( find -type f -\( -iname '*.exe' -o -iname '*.iso' -\) -printf '%P\0' ) + done < <( find . -type f -\( -iname '*.exe' -o -iname '*.iso' -\) -printf '%P\0' ) sums_update ${paths[@]+"${paths[@]}"} ) diff --git a/%HOME%/.bash_utils/path.sh b/%HOME%/.bash_utils/path.sh index 13b5b00..57f1ab5 100644 --- a/%HOME%/.bash_utils/path.sh +++ b/%HOME%/.bash_utils/path.sh @@ -12,11 +12,11 @@ add_missing_path() ( [ "$#" -eq 0 ] && return 0 - local -a new_list + local -a src_list local path while IFS= read -d '' -r path; do - new_list+=("$path") + src_list+=("$path") done < <( readlink -z --canonicalize-missing -- "$@" ) for path; do @@ -26,23 +26,23 @@ add_missing_path() ( fi done - local -A old_dict - local -a old_list + local -A dest_dict + local -a dest_list if [ -n "${PATH-}" ]; then while IFS= read -d '' -r path; do - old_dict[$path]=1 - old_list+=("$path") + dest_dict[$path]=1 + dest_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") + for path in ${src_list[@]+"${src_list[@]}"}; do + [ -n "${dest_dict[$path]+x}" ] && continue + dest_dict[$path]=1 + dest_list+=("$path") done - str_join ':' ${old_list[@]+"${old_list[@]}"} + str_join ':' ${dest_list[@]+"${dest_list[@]}"} ) add_path() { -- cgit v1.2.3