Skip to content

Instantly share code, notes, and snippets.

@kevinohara80
Last active December 11, 2015 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinohara80/4551355 to your computer and use it in GitHub Desktop.
Save kevinohara80/4551355 to your computer and use it in GitHub Desktop.
Here is my command prompt from my .bash_profile. The command prompt detects whether it's in a git project or not and if it is, it indicates the current branch and whether there are un-staged changes pending.
# RETURN ASTERISK WHEN CHANGES ARE PRESENT BUT UNSTAGED
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
# GET THE CURRENT GIT BRANCH
function parse_git_branch() {
if [ -d "./.git" ]; then
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
fi
}
# ANSI COLORS
RED="\[\033[0;31m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[0;32m\]"
CYAN="\[\033[0;36m\]"
BLUE="\[\033[0;34m\]"
LGRAY="\[\033[0;37m\]"
DGRAY="\[\033[1;30m\]"
RESET="\[\033[0m\]"
# BASH PROMPT
export PS1="$DGRAY\w$BLUE \$(parse_git_branch)\n$GREEN\[\e[32m\]λ:$RESET "
@kevinohara80
Copy link
Author

Preview:

Git-enabled Bash Promptt

@kevinohara80
Copy link
Author

NOTE: since checking ./.git is only checking the root directory, the git branch will not show if you are in a sub-directory of a git repo. I sort of want mine to work this way because it's better than calling git branch at every prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment