parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1="[\u@\h \W\$(parse_git_branch)]\$ " parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1="[\u@\h \W\$(parse_git_branch)]\$ "Internally, symbolic-ref resolve the ref in the same way as git branch, just without handling detached HEAD. __git_ps1 use a combination of rev-parse, symbolic-ref and git describe to provide a more interesting output for displaying state of the working directory.
To have the similar output for detached HEAD as git-status (e.g. "HEAD detached at fa0c4e1") then probably `git rev-parse --abbrev-rev` and `git rev-parse --short` should be used together. Unfortunately, while rev-parse can print multiple output in a single command, abbrev-rev and short cannot be used together. In such case, parsing `git status` might indeed be more suitable as it spawn only one executable instead of two.
Some porcelain commands do have --porcelain flag to ensure the stability of the interface, though (e.g. `git status --porcelain=v1`).
git branch --show-current
See https://git-scm.com/docs/git-branch if [ "$color_prompt" = yes ]; then
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\
[\033[0;36m\] @ \[\033[0;36m\]\h \w\
[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\
[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]
AWS:${AWS_PROFILE} ▶\[\033[0m\] '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fiexport PS1="\n\$(kube_ps1)\n\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[0;31m\]\$(__git_ps1)\n\$\[\033[00m\] "
Note it needs the git-prompt.sh script (usually comes with the bash-completion package), and the kube-ps1 script: https://github.com/jonmosco/kube-ps1
It will show you the current kubernetes profile and namespace, user@host, current directory and git branch if you're in a git repo.