lib/helpers: cite `_bash-it-find-in-ancestor()`
Add `composure.sh` citation with examples and rewrite internal comments to describe the code flow.pull/1952/head
parent
7ed12083f2
commit
e8966ea2a5
|
|
@ -850,12 +850,21 @@ then
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in
|
||||||
|
# a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]`
|
||||||
|
# without any external dependencies. Let the shell do what it's good at.
|
||||||
function _bash-it-find-in-ancestor() (
|
function _bash-it-find-in-ancestor() (
|
||||||
# We're deliberately using a subshell for this entire function for simplicity.
|
about 'searches parents of the current directory for any of the specified file names'
|
||||||
# By using a subshell, we can use ${PWD} without special handling, and can
|
group 'helpers'
|
||||||
# just `cd ..` to move up the directory heirarchy.
|
param '*: names of files or folders to search for'
|
||||||
# Let the shell do the work.
|
returns '0: prints path of closest matching ancestor directory to stdout'
|
||||||
|
returns '1: no match found'
|
||||||
|
returns '2: improper usage of shell builtin' # uncommon
|
||||||
|
example '_bash-it-find-in-ancestor .git .hg'
|
||||||
|
example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile'
|
||||||
|
|
||||||
local kin
|
local kin
|
||||||
|
# To keep things simple, we do not search the root dir.
|
||||||
while [[ "${PWD}" != '/' ]]; do
|
while [[ "${PWD}" != '/' ]]; do
|
||||||
for kin in "$@"; do
|
for kin in "$@"; do
|
||||||
if [[ -r "${PWD}/${kin}" ]]; then
|
if [[ -r "${PWD}/${kin}" ]]; then
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue