diff --git a/helper.zsh b/helper.zsh index dd101a5..1b40161 100644 --- a/helper.zsh +++ b/helper.zsh @@ -15,6 +15,15 @@ function is-true() { [[ -n "$1" && "$1" == (1|[Yy]([Ee][Ss]|)|[Tt]([Rr][Uu][Ee]|)|[Oo]([Nn]|)) ]] } +# Prints the first non-empty string in the arguments array. +function coalesce() { + for arg in "$argv[@]"; do + print "$arg" + return 0 + done + return 1 +} + # Trap signals were generated with 'kill -l'. # DEBUG, EXIT, and ZERR are Zsh signals. TRAP_SIGNALS=( diff --git a/plugins/git/functions/git-info b/plugins/git/functions/git-info index 8e551ae..0b13982 100644 --- a/plugins/git/functions/git-info +++ b/plugins/git/functions/git-info @@ -140,7 +140,6 @@ function git-info() { local clean local clean_formatted local commit - local commit_short local commit_format local deleted=0 local deleted_format @@ -220,9 +219,8 @@ function git-info() { commit="$(git rev-parse HEAD 2>/dev/null)" # Format commit (short). - commit_short="$commit[1,7]" zstyle -s ':omz:plugin:git:prompt' commit 'commit_format' - zformat -f commit_formatted "$commit_format" "c:$commit_short" + zformat -f commit_formatted "$commit_format" "c:$commit" # Stashed if [[ -f "$(_git-dir)/refs/stash" ]]; then @@ -238,9 +236,6 @@ function git-info() { (( line_number++ )) if (( line_number == 1 )) && [[ "$line" == *'(no branch)'* ]]; then - # Set branch to commit (short) when the branch is not found. - branch="$commit_short" - # Get action. action="$(_git-action)" if [[ -n "$action" ]]; then diff --git a/themes/sorin/prompt_sorin_setup b/themes/sorin/prompt_sorin_setup index a1aafbf..e6f4a86 100644 --- a/themes/sorin/prompt_sorin_setup +++ b/themes/sorin/prompt_sorin_setup @@ -35,12 +35,12 @@ function prompt_sorin_setup() { zstyle ':omz:plugin:git:prompt' deleted ' %%B%F{red}✖%f%%b' zstyle ':omz:plugin:git:prompt' modified ' %%B%F{blue}✱%f%%b' zstyle ':omz:plugin:git:prompt' renamed ' %%B%F{magenta}➜%f%%b' - zstyle ':omz:plugin:git:prompt' commit '%c' + zstyle ':omz:plugin:git:prompt' commit '%.7c' zstyle ':omz:plugin:git:prompt' stashed ' %%B%F{cyan}✭%f%%b' zstyle ':omz:plugin:git:prompt' unmerged ' %%B%F{yellow}═%f%%b' zstyle ':omz:plugin:git:prompt' untracked ' %%B%F{white}◼%f%%b' - zstyle ':omz:plugin:git:prompt' prompt ' %F{blue}git%f%b%s' zstyle ':omz:plugin:git:prompt' rprompt '%A%B%S%a%d%m%r%U%u' + zstyle -e ':omz:plugin:git:prompt' prompt 'reply=("%F{blue}git%f$(coalesce "%b" "%c")%s")' PROMPT='%F{cyan}%1~%f${git_prompt_info} %(!.%B%F{red}#%f%b.%B%F{green}❯%f%b) ' RPROMPT='%(?::%F{red}⏎%f)${VIM:+" %B%F{green}V%f%b"}${git_rprompt_info}'