Skip to content

Instantly share code, notes, and snippets.

@bsdf
Created May 17, 2020 16:56
Show Gist options
  • Save bsdf/6b11c907e8baa3f68adc47fc7959d0fa to your computer and use it in GitHub Desktop.
Save bsdf/6b11c907e8baa3f68adc47fc7959d0fa to your computer and use it in GitHub Desktop.
# -*- 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