chore(zsh): update prompt

Ensure that the branch name and commit SHA update without needing to
source the config file again.
This commit is contained in:
Oliver Davies 2022-07-12 19:48:45 +01:00
parent c2bad3cf32
commit 3dfa00942d

View file

@ -1,15 +1,15 @@
source $ZDOTDIR/oh-my-zsh/git.zsh
setopt prompt_subst
git_prompt_prefix() {
local tag="$(git describe --tags 2> /dev/null)"
git_branch() {
local branch="$(git symbolic-ref HEAD 2> /dev/null | cut -d'/' -f3)"
[ -n "${tag}" ] && echo "%{$fg[yellow]%}${tag}%{$reset_color%} "
[ -n "${branch}" ] && echo " (${branch})"
}
git_prompt_suffix() {
local branch="$(git_current_branch)"
git_commit() {
local commit_sha="$(git rev-parse --short HEAD 2> /dev/null)"
[ -n "${branch}" ] && echo " on %{$fg[green]%}${branch}%{$reset_color%}"
[ -n "${commit_sha}" ] && echo " [${commit_sha}]"
}
export PS1="$(git_prompt_prefix)in %{$fg[blue]%}%1d/%{$reset_color%}$(git_prompt_suffix) "
export PS1='%{$fg[blue]%}%1d%{$reset_color%}%{$fg[green]%}$(git_branch)%{$reset_color%}%{$fg[yellow]%}$(git_commit)%{$reset_color%} $ '