Skip to content

Instantly share code, notes, and snippets.

@jonathanbardo
Last active August 29, 2015 14:16
Show Gist options
  • Save jonathanbardo/bb62ca1de747155054dd to your computer and use it in GitHub Desktop.
Save jonathanbardo/bb62ca1de747155054dd to your computer and use it in GitHub Desktop.
GIT PS1
#!/usr/bin/env bash
function BEFORE_PS1 {
printf "\e[32m[\e[0m$(whoami)\e[32m]@[\e[0mlocal\e[32m][\e[0m${PWD/#$HOME/~}\e[32m]$(gitPS1)\e[0m"
}
#!/usr/bin/env bash
#Color the bash PS1
function gitPS1 {
gitBranch=$(git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/\1/')
if [ "x$gitBranch" == "x" ]; then
echo ""
else
gitStatus=$(echo `git status` | grep 'nothing to commit' > /dev/null 2>&1)
if [ $? -eq 0 ]; then
printf "\e[32m[\e[32m$gitBranch\e[32m]\e[0m"
else
gitStatus=$(echo `git status` | grep "ntracked" > /dev/null 2>&1)
if [ $? -eq 0 ]; then
printf "\e[32m[\e[31m$gitBranch\e[32m]\e[0m"
else
printf "\e[32m[\e[33m$gitBranch\e[32m]\e[0m"
fi
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment