Created
May 17, 2020 16:56
-
-
Save bsdf/6b11c907e8baa3f68adc47fc7959d0fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- mode: sh; -*- | |
gtfo() { | |
FILE=${1:-.git} | |
MAX_DEPTH=${2:-10} | |
SAVED="$PWD" | |
i=0 | |
while [ "$i" -lt "$MAX_DEPTH" ] && [ ! -e "$FILE" ] | |
do | |
cd .. || exit | |
i=$((i+1)) | |
done | |
# needed because `cd -` in zsh does not respect $OLDPWD | |
cd "$SAVED" || exit | |
cd - || exit | |
OLDPWD="$SAVED" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment