Skip to content

Instantly share code, notes, and snippets.

@dariok
Last active May 25, 2023 07:16
Show Gist options
  • Save dariok/0205036e6d4c473a05a9469022f87f3f to your computer and use it in GitHub Desktop.
Save dariok/0205036e6d4c473a05a9469022f87f3f to your computer and use it in GitHub Desktop.
bash prompt with date, time and git branch
# 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\] '
@dariok
Copy link
Author

dariok commented Mar 24, 2021

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