Skip to content

Instantly share code, notes, and snippets.

@blockloop
Created January 7, 2016 05:34
Show Gist options
  • Save blockloop/353770cec31f5b82a8a7 to your computer and use it in GitHub Desktop.
Save blockloop/353770cec31f5b82a8a7 to your computer and use it in GitHub Desktop.
Search upward to find a certain file or directory. I don't know where I found this or if I wrote it myself.
upsearch() {
origdir=${2-$(pwd)}
test / == "$PWD" && cd "$origdir" && return || \
test -e "$1" && echo "$PWD" && cd "$origdir" && return || \
cd .. && upsearch "$1" "$origdir"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment