Skip to content

Commit bf63066

Browse files
committed
lib/helpers: cite _bash-it-find-in-ancestor()
Add `composure.sh` citation with examples and rewrite internal comments to describe the code flow.
1 parent 7ed1208 commit bf63066

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/helpers.bash

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,21 @@ then
850850
}
851851
fi
852852

853+
# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in
854+
# a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]`
855+
# without any external dependencies. Let the shell do what it's good at.
853856
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.
857+
about 'searches parents of the current directory for any of the specified file names'
858+
group 'helpers'
859+
param '*: names of files or folders to search for'
860+
returns '0: prints path to matching parent directory to stdout'
861+
returns '1: no match found'
862+
returns '2: improper usage of shell builtin' # uncommon
863+
example '_bash-it-find-in-ancestor .git .hg'
864+
example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile'
865+
858866
local kin
867+
# To keep things simple, we do not search the root dir.
859868
while [[ "${PWD}" != '/' ]]; do
860869
for kin in "$@"; do
861870
if [[ -r "${PWD}/${kin}" ]]; then

0 commit comments

Comments
 (0)