Skip to content

Instantly share code, notes, and snippets.

@GalassoLuca
Last active December 16, 2021 10:19
Show Gist options
  • Save GalassoLuca/a502c3ba2489b6fae7270f5653bedfc0 to your computer and use it in GitHub Desktop.
Save GalassoLuca/a502c3ba2489b6fae7270f5653bedfc0 to your computer and use it in GitHub Desktop.
Upwards find: find the first filename backward from the current folder to the root
# Upwards find
## Description: find the first filename backward from the current folder to the root
upfind() {
folder="$(pwd)"
while [ "$folder" != "/" ]; do
for arg in "$@"; do
if [ -e "${folder}/$arg" ]; then
echo $folder/$arg
folder="/"
fi
done
folder="$(dirname "$folder")"
done
}
upfind "$@"
## Usage
# upfind .gitignore
# upfind .nvmrc .node-version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment