Skip to content

Instantly share code, notes, and snippets.

@Deliaz
Created January 25, 2023 10:44
Show Gist options
  • Save Deliaz/2d40e9ed666057d7aa913825b315d1fb to your computer and use it in GitHub Desktop.
Save Deliaz/2d40e9ed666057d7aa913825b315d1fb to your computer and use it in GitHub Desktop.
#CUSTOM
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats ' (%b)'
setopt PROMPT_SUBST
PROMPT=$'%B%(?.%F{green}✔.%F{red}✘) %F{cyan}%* %F{green}[%(!.%F{red}.%F{yellow})%n%F{red}@%F{red}%m%F{red} %F{cyan}%~%F{green}${vcs_info_msg_0_}] \n%F{blue}%(!.#.$) %f%b'
@Deliaz
Copy link
Author

Deliaz commented Jan 25, 2023

Outputs:

✔ 10:44:20 [user@machine ~/code (main)] 

@Deliaz
Copy link
Author

Deliaz commented Jul 10, 2025

#CUSTOM

# Load vcs_info
autoload -Uz vcs_info

# Git hook: inject branch + dirty status with colors
function +vi-git-custom-hook() {
  local status_output=$(git status --porcelain 2>/dev/null)
  local modified_count=$(echo "$status_output" | grep -c '^[^?]' 2>/dev/null)
  local untracked_count=$(echo "$status_output" | grep -c '^??' 2>/dev/null)

  modified_count=${modified_count:-0}
  untracked_count=${untracked_count:-0}

  if [[ "$modified_count" -eq 0 && "$untracked_count" -eq 0 ]]; then
    hook_com[branch]="%F{green}(${hook_com[branch]})%f"
  else
    hook_com[branch]="%F{green}(${hook_com[branch]};%F{yellow}${modified_count}~${untracked_count}%F{green})%f"
  fi
}

# Only show in Git repos
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git:*' formats '%b'  # no () here
zstyle ':vcs_info:git+set-message:*' hooks git-custom-hook

# Trigger vcs_info before each prompt
precmd() { vcs_info }

# Enable prompt substitution
setopt PROMPT_SUBST

# Final prompt string
PROMPT=$'%B%(?.%F{green}✔.%F{red}✘) %F{cyan}%* %f[%(!.%F{red}.%F{yellow})%n%F{red}@%F{red}%m%F{red} %F{cyan}%~ ${vcs_info_msg_0_}]%f \n%F{blue}%(!.#.$) %f%b'

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