Last active
August 11, 2017 17:35
-
-
Save itsthatguy/db2a8d6ebed178b66abef8a2e861a366 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
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