Skip to content

Commit ef16567

Browse files
committed
lib/helpers: rename and rewrite _bash_it_find_in_ancestor()
1 parent b38812e commit ef16567

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

lib/helpers.bash

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -850,21 +850,20 @@ then
850850
}
851851
fi
852852

853-
function _bash_it_find_kin()
854-
(
855-
# We're deliberately using a subshell for this entire function for simplicity.
856-
# By using a subshell, we can use ${PWD} without special handling, and can
857-
# just `cd ..` to move up the directory heirarchy. Let the shell do the work.
858-
local common_ancestor="${PWD}"
859-
local uncle="${1?${FUNCNAME[0]}: a file to locate must be specified}" aunt="${2:-}"
860-
while [[ "${PWD:-/}" != '/' ]]
861-
do
862-
if [[ -r "${PWD}/${uncle}" || -r "${aunt:+${PWD}/}${aunt:-}" ]]
863-
then
864-
common_ancestor="${PWD}"
865-
echo "${common_ancestor}"
866-
return 0
867-
fi
853+
function _bash_it_find_in_ancestor() (
854+
# We're deliberately using a subshell for this entire function for simplicity.
855+
# By using a subshell, we can use ${PWD} without special handling, and can
856+
# just `cd ..` to move up the directory heirarchy.
857+
# Let the shell do the work.
858+
local common_ancestor="${PWD}" kin
859+
while [[ "${PWD:-/}" != '/' ]]; do
860+
for kin in "$@"; do
861+
if [[ -r "${PWD}/${kin}" ]]; then
862+
common_ancestor="${PWD}"
863+
echo "${common_ancestor}"
864+
return 0
865+
fi
866+
done
868867
command cd .. || return 2
869868
done
870869
return 1

0 commit comments

Comments
 (0)