Skip to content

Instantly share code, notes, and snippets.

@josh-taylor
Last active December 21, 2015 10:29
Show Gist options
  • Save josh-taylor/6292249 to your computer and use it in GitHub Desktop.
Save josh-taylor/6292249 to your computer and use it in GitHub Desktop.
My PS1 that displays the current branch in red
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