zsh: show git branch in prompt

This commit is contained in:
Dmitry Zakharchenko 2023-01-05 16:04:07 +02:00
parent 7dca2eb32b
commit 690d76a57b
1 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,16 @@
# Enable colors and change prompt:
git_prompt() {
local branch="$(git symbolic-ref HEAD 2> /dev/null | cut -d'/' -f3-)"
local branch_truncated="${branch:0:30}"
if (( ${#branch} > ${#branch_truncated} )); then
branch="${branch_truncated}..."
fi
[ -n "${branch}" ] && echo " (${branch})"
}
setopt PROMPT_SUBST
autoload -U colors && colors # Load colors
PROMPT='%1~%f%b $ '
PROMPT='%1~%f%b%F{blue}$(git_prompt)%f $ '
# gpg key for ssh authentication
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"