lib/helpers: new function `_bash-it-find-in-ancestor()`
New function to do a search looking for a sibling to a parent of the current directory, for example to find `../../.git` to indicate that `$PWD` is inside a git repository.pull/1952/head
parent
8c697715eb
commit
0471a20c7c
|
|
@ -849,3 +849,21 @@ then
|
|||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
function _bash-it-find-in-ancestor() (
|
||||
# We're deliberately using a subshell for this entire function for simplicity.
|
||||
# By using a subshell, we can use ${PWD} without special handling, and can
|
||||
# just `cd ..` to move up the directory heirarchy.
|
||||
# Let the shell do the work.
|
||||
local kin
|
||||
while [[ "${PWD}" != '/' ]]; do
|
||||
for kin in "$@"; do
|
||||
if [[ -r "${PWD}/${kin}" ]]; then
|
||||
printf '%s' "${PWD}"
|
||||
return "$?"
|
||||
fi
|
||||
done
|
||||
command cd .. || return "$?"
|
||||
done
|
||||
return 1
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue