Last active
October 9, 2023 15:13
-
-
Save franciscop/3b62a662f99d8b3b05ea732d429f2dff to your computer and use it in GitHub Desktop.
Theme for ZSH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function git_prompt_info() { | |
# If we are on a folder not tracked by git, get out. | |
# Otherwise, check for hide-info at global and local repository level | |
if ! __git_prompt_git rev-parse --git-dir &> /dev/null \ | |
|| [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then | |
return 0 | |
fi | |
local ref | |
ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \ | |
|| ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \ | |
|| ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \ | |
|| return 0 | |
# Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info | |
local upstream | |
if (( ${+ZSH_THEME_GIT_SHOW_UPSTREAM} )); then | |
upstream=$(__git_prompt_git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" 2>/dev/null) \ | |
&& upstream=" -> ${upstream}" | |
fi | |
echo "$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}${ZSH_THEME_GIT_PROMPT_SUFFIX}" | |
} | |
PROMPT='%{$fg_bold[cyan]%}%c%{$reset_color%}$(git_prompt_info)%{$fg_bold[green]%} ➜ %{$reset_color%}' | |
ZSH_THEME_GIT_PROMPT_PREFIX="[" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="]" | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[yellow]%}" | |
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[grey]%}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment