Skip to content

Instantly share code, notes, and snippets.

@itsthatguy
Last active August 11, 2017 17:35
Show Gist options
  • Save itsthatguy/db2a8d6ebed178b66abef8a2e861a366 to your computer and use it in GitHub Desktop.
Save itsthatguy/db2a8d6ebed178b66abef8a2e861a366 to your computer and use it in GitHub Desktop.
function git_dir_helper() {
current_dir=${PWD##*/}
if git rev-parse --git-dir > /dev/null 2>&1 && [ ! -d .git ]; then
git_dir_cdup=$(git rev-parse --show-cdup)
git_dir_path=$(git rev-parse --show-prefix)
git_dir_top="$(
cd $git_dir_cdup > /dev/null
echo ${PWD##*/}
)"
current_dir="$git_dir_top/${git_dir_path%/}"
fi
echo -n $current_dir
}
function bash_prompt_command() {
current_dir=$(git_dir_helper)
PS1="$current_dir"
}
# Using with bash
PROMPT_COMMAND=bash_prompt_command
# Using with zsh
function precmd {
PROMPT="$(itg_dir)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment