Last active
December 21, 2015 10:29
-
-
Save josh-taylor/6292249 to your computer and use it in GitHub Desktop.
My PS1 that displays the current branch in red
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
color_enabled() { | |
test -x /usr/bin/tput | |
} | |
BRANCH_FORMAT=$(color_enabled && tput setaf 2) | |
DIR_FORMAT=$(color_enabled && tput setaf 6) | |
RESET_FORMAT=$(color_enabled && tput sgr0) | |
function git_info() { | |
git rev-parse --is-inside-work-tree &>/dev/null || return | |
branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||') | |
dirty=$(git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ]&& echo -e "*") | |
echo $BRANCH_FORMAT$branch$dirty | |
} | |
PS1="\h at \[$DIR_FORMAT\]\w\[$RESET_FORMAT\] on \$(git_info) \[$RESET_FORMAT\] \n\$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment