Last active
December 16, 2021 10:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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