Skip to content

Instantly share code, notes, and snippets.

@Querela
Forked from notmatt/gist:1613012
Created May 10, 2017 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Querela/6596ab1d5ce7934f8827113c6b0591ae to your computer and use it in GitHub Desktop.
Save Querela/6596ab1d5ce7934f8827113c6b0591ae to your computer and use it in GitHub Desktop.
git ps1
# GIT PS1
# COLORS
LIGHT_GRAY="\[\033[0;37m\]"; BLUE="\[\033[0;34m\]"; RED="\[\033[0;31m\]"; LIGHT_RED="\[\033[1;31m\]";
GREEN="\[\033[0;32m\]"; WHITE="\[\033[1;37m\]"; LIGHT_GRAY="\[\033[0;37m\]"; YELLOW="\[\033[1;33m\]";
BROWN="\[\033[0;33m\]"; BLACK="\[\033[0;30m\]";PURPLE="\[\033[0;35m\]";CYAN="\[\033[0;36m\]";
# GIT PROMPT (http://gist.github.com/120804)
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/';
}
function parse_git_status {
git status 2> /dev/null | sed -e '/(working directory clean)$/!d' | wc -l;
}
function check_git_changes {
# tput setaf 1 = RED, tput setaf 2 = GREEN
[ `parse_git_status` -ne 1 ] && tput setaf 1 || tput setaf 2
}
export PS1="$CYAN\$(date +%H:%M) $BLUE\w\[\$(check_git_changes)\]\$(parse_git_branch)$BLACK $ "
# GIT CHECKOUT AUTOCOMPLETE
_complete_git() {
if [ -d .git ]; then
branches=`git branch -a | cut -c 3-`
tags=`git tag`
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${branches} ${tags}" -- ${cur}) )
fi
}
complete -F _complete_git git checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment