Created
December 8, 2008 10:57
-
-
Save jdelStrother/33425 to your computer and use it in GitHub Desktop.
This file contains 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
precmd() { | |
local branch_ref branchless_ref | |
psvar=() | |
branch_ref=$(git symbolic-ref -q HEAD 2>/dev/null) | |
cleanliness="" | |
if [[ ! -z $(git diff-index --name-only HEAD 2>/dev/null) ]]; then | |
cleanliness="*" | |
fi | |
# We might be on a checked out branch: | |
if [[ ! -z "$branch_ref" ]]; then | |
psvar[1]=$cleanliness${branch_ref#refs/heads/} | |
else | |
branchless_ref=$(git name-rev --name-only HEAD 2>/dev/null) | |
if [[ ! -z "$branchless_ref" ]]; then | |
# Or we might happen to be on the same commit as (eg) master, but not have it checked out | |
psvar[2]=$cleanliness${branchless_ref#(refs/heads/|remotes/)}$cleanliness | |
fi | |
fi | |
} | |
export PS1="[$PR_GREEN%n$PR_WHITE@$PR_GREEN%U%m%u$PR_NO_COLOR:$PR_RED%2c$PR_NO_COLOR]%(?.$.!) " # username, underlined host, 2 levels of current directory, '$' if last command succeeded, '!' otherwise. | |
# right-hand prompt: | |
BRANCH_PROMPT="{$PR_LIGHT_GREEN%1v$PR_NO_COLOR}" | |
HEADLESS_PROMPT="{$PR_LIGHT_RED%2v$PR_NO_COLOR}" | |
# if psvar has 2 elements, we're not on a branch, but still have a suitable git name to use. | |
# if psvar has 1 element, we're on a checked out branch (and obviously have a suitable git name to use) | |
# otherwise, use a blank right-prompt. | |
export RPS1="%(2v.$HEADLESS_PROMPT.%(1v.$BRANCH_PROMPT.))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment