Last active
May 25, 2023 07:16
-
-
Save dariok/0205036e6d4c473a05a9469022f87f3f to your computer and use it in GitHub Desktop.
bash prompt with date, time and git branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Path for openSuSE – may be different in other distributions | |
source /usr/share/bash-completion/completions/git-prompt.sh | |
# taken from https://github.com/qupada/git-bashrc/blob/master/git-bashrc | |
_in_git_repo () { | |
# Check the current dir is actually a repository | |
git status &> /dev/null || return 2 | |
# If we are not on a branch we will get annoying errors if we don't do this check | |
git branch | grep -qE '^\* \((no branch|detached from .*)\)' && return 1 | |
return 0 | |
} | |
_getStats () { | |
# we assume to always have a remote | |
ahead=`git rev-list --count @{u}..HEAD` | |
behind=`git rev-list --count HEAD..@{u}` | |
echo "↑ $ahead ↓ $behind" | |
} | |
_git_stats () { | |
_in_git_repo && _getStats | |
} | |
export PS1='\033[35m[\D{%a %T}]\[\033[0m\]\[\033[0;32m\] \[\033[0m\033[0;32m\]\u\[\033[0;36m\]@\[\033[0;36m\]\h:\ | |
\w\[\033[0;32m\]$(__git_ps1) $(_git_stats)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on https://gist.github.com/justintv/168835#gistcomment-1717504