From da96f0334f80ab7564b4b8411d8bfccaf3bcadb4 Mon Sep 17 00:00:00 2001 From: Robin Bowes Date: Mon, 19 Feb 2024 16:56:18 +0000 Subject: [PATCH 1/2] style: alternate approach to sorting paths --- hooks/_common.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index d6dbbb272..56adc3738 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -348,8 +348,12 @@ function common::per_dir_hook { local pids=() - # shellcheck disable=SC2207 # More readable way - local -a dir_paths_unique=($(printf '%s\n' "${dir_paths[@]}" | sort -u)) + # Note: This can break if any elements of dir_path contain glob characters. + # However, all elements of dir_path are generated from the output of dirname + # Which means all glob characters will already have been expanded. + # shellcheck disable=SC2207 # Can't use mapfile in bash 3 + IFS=$'\n' local -a dir_paths_unique=($(sort -u <<<"${dir_paths[*]}")) + unset IFS local length=${#dir_paths_unique[@]} local last_index=$((${#dir_paths_unique[@]} - 1)) From 2855eda2b450a53fc3948073e08fb504a4e46803 Mon Sep 17 00:00:00 2001 From: Robin Bowes Date: Mon, 19 Feb 2024 17:37:17 +0000 Subject: [PATCH 2/2] refactor: silence shfmt's griping --- hooks/_common.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/_common.sh b/hooks/_common.sh index 56adc3738..4f6610d22 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -348,11 +348,12 @@ function common::per_dir_hook { local pids=() + local -a dir_paths_unique # Note: This can break if any elements of dir_path contain glob characters. # However, all elements of dir_path are generated from the output of dirname # Which means all glob characters will already have been expanded. # shellcheck disable=SC2207 # Can't use mapfile in bash 3 - IFS=$'\n' local -a dir_paths_unique=($(sort -u <<<"${dir_paths[*]}")) + IFS=$'\n' dir_paths_unique=($(sort -u <<< "${dir_paths[*]}")) unset IFS local length=${#dir_paths_unique[@]}