Skip to content

Commit

Permalink
style: alternate approach to sorting paths
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbowes committed Feb 19, 2024
1 parent 385b542 commit da96f03
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hooks/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit da96f03

Please sign in to comment.