Skip to content

Instantly share code, notes, and snippets.

@clauda
Created February 17, 2011 02:55
Show Gist options
  • Save clauda/830860 to your computer and use it in GitHub Desktop.
Save clauda/830860 to your computer and use it in GitHub Desktop.
adaptado de outros. for git users.
function git_state {
if [[ $(which git 2> /dev/null) ]]
then
local STATUS
local GIT_STATUS
GIT_STATE=""
STATUS=$(git status 2>/dev/null)
if [[ -z $STATUS ]]
then
return
fi
if [[ "$STATUS" == *'working directory clean'* ]]
then
GIT_STATE=""
else
GIT_HEAD=$GIT_HEAD":"
GIT_STATE=""
if [[ "$STATUS" == *'Changes to be committed:'* ]]
then
GIT_STATE=$GIT_STATE'+I' # Index has files staged for commit
fi
if [[ "$STATUS" == *'Changed but not updated:'* ]]
then
GIT_STATE=$GIT_STATE"+M" # Working tree has files modified but unstaged
fi
if [[ "$STATUS" == *'Untracked files:'* ]]
then
GIT_STATE=$GIT_STATE'+U' # Working tree has untracked files
fi
fi
echo "${GIT_STATE} "
fi
}
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "["${ref#refs/heads/}"]"
}
function get_author {
echo $(git config user.name)
}
GREEN="\[\033[01;32m\]"
BLUE="\[\033[01;34m\]"
WHITE="\[\033[00m\]"
YELLOW="\[\033[0;33m\]"
RED="\[\033[1;31m\]"
export PS1="$GREEN\h $WHITE~\W $BLUE\$(get_author)$YELLOW \$(parse_git_branch)$RED\$(git_state)$WHITE$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment