diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-04-16 01:54:48 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-04-16 01:54:48 +0300 |
commit | c28e0a6eb6a99c1bd3450a3ad2a38ff4c6e8bea7 (patch) | |
tree | 0f85688cd531442bac740ee824e6d18c0a1f8c46 | |
parent | backup_gitconfig.sh -> configure_git.sh (diff) | |
download | linux-home-c28e0a6eb6a99c1bd3450a3ad2a38ff4c6e8bea7.tar.gz linux-home-c28e0a6eb6a99c1bd3450a3ad2a38ff4c6e8bea7.zip |
sums_list_paths: factor out sums_unescape_path
-rw-r--r-- | %HOME%/.bash_utils/distr.sh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/%HOME%/.bash_utils/distr.sh b/%HOME%/.bash_utils/distr.sh index 7d67a10..ff32c0a 100644 --- a/%HOME%/.bash_utils/distr.sh +++ b/%HOME%/.bash_utils/distr.sh @@ -6,6 +6,18 @@ # Distributed under the MIT License. sums_path='sha1sums.txt' +sums_name="$( basename -- "$sums_path" )" + +sums_unescape_path() { + if [ "$#" -ne 1 ]; then + echo "usage: ${FUNCNAME[0]} PATH" >&2 + return 1 + fi + local path="$1" + path="${path//'\\'/$'\\'}" + path="${path//'\n'/$'\n'}" + echo "$path" +} sums_list_paths() ( set -o errexit -o nounset -o pipefail @@ -43,10 +55,7 @@ sums_list_paths() ( fi IFS= read -r path path="${path#'*'}" - if [ -n "$escaped" ]; then - path="${path//'\\'/$'\\'}" - path="${path//'\n'/$'\n'}" - fi + [ -n "$escaped" ] && path="$( sums_unescape_path "$path" )" paths+=("$path") done < "$sums_path" @@ -82,7 +91,7 @@ sums_add_all() ( while IFS= read -d '' -r path; do paths+=("$path") - done < <( find . -type f -\! -name "$( basename -- "$sums_path" )" -printf '%P\0' ) + done < <( find . -type f -\! -iname "$sums_name" -printf '%P\0' ) sums_add ${paths[@]+"${paths[@]}"} ) |