Last active
March 19, 2023 22:59
-
-
Save igorjs/8de2fb287e9f40df8d5b96e295c2ef18 to your computer and use it in GitHub Desktop.
Oh My ZSH Custom Theme
This file contains hidden or 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
# prompt cursor fix when exiting vim | |
echo -en '\e[0 q' | |
prompt_symbol() { | |
local symbol="➜" | |
if [[ $UID -eq 0 ]]; then | |
symbol="#" | |
fi | |
symbol="%{$fg_bold[grey]%}${symbol}%{$reset_color%}" | |
echo -n "$symbol" | |
} | |
# Git: branch/detached head, dirty status | |
prompt_git() { | |
(( $+commands[git] )) || return | |
local LC_ALL="" | |
local LC_CTYPE="en_US.UTF-8" | |
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then | |
local repo_path=$(git rev-parse --git-dir 2>/dev/null) | |
local ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)" | |
local untracked=$(git status --porcelain 2>/dev/null | grep '^??') | |
local untracked_status="" | |
if [[ -n "$untracked" ]]; then | |
untracked_status="%{$fg_bold[red]%}✗ %{$reset_color%}" | |
fi | |
local ahead=$(git log --oneline @{upstream}.. 2>/dev/null) | |
local behind=$(git log --oneline ..@{upstream} 2>/dev/null) | |
local ahead_count=$([[ -z "$ahead" ]] && echo 0 || echo "$ahead" | wc -l | xargs) | |
local behind_count=$([[ -z "$behind" ]] && echo 0 || echo "$behind" | wc -l | xargs) | |
local pl_branch_char=$'\ue0a0' | |
local pl_branch_status="" | |
if [[ -n "$ahead" ]] && [[ -n "$behind" ]]; then | |
pl_branch_status=" ↑${ahead_count} ↓${behind_count}" | |
elif [[ -n "$ahead" ]]; then | |
pl_branch_status=" ↑${ahead_count}" | |
elif [[ -n "$behind" ]]; then | |
pl_branch_status=" ↓${behind_count}" | |
fi | |
pl_branch_char="%{$fg_bold[blue]%}${pl_branch_char}%{$reset_color%}" | |
pl_branch_status="%{$fg_no_bold[green]%}${pl_branch_status}%{$reset_color%}" | |
setopt promptsubst | |
autoload -Uz vcs_info | |
zstyle ':vcs_info:*' enable git | |
zstyle ':vcs_info:*' get-revision true | |
zstyle ':vcs_info:*' check-for-changes true | |
zstyle ':vcs_info:*' check-for-staged-changes true | |
zstyle ':vcs_info:*' unstagedstr "%{${fg_bold[yellow]}%}± " | |
zstyle ':vcs_info:*' stagedstr "%{${fg_bold[green]}%}+ " | |
zstyle ':vcs_info:*' formats " %{${fg_bold[blue]}%}(%b) %m%c%u" | |
zstyle ':vcs_info:*' actionformats " %{${fg_bold[blue]}%}(%b) %{${fg_no_bold[red]}%}[%a] %m%c%u" | |
vcs_info | |
echo -n "${pl_branch_char}${pl_branch_status}${vcs_info_msg_0_%%}${untracked_status}" | |
fi | |
} | |
## Main prompt | |
PROMPT='%(!.%{$fg[red]%}.%{$fg[green]%})%~ $(prompt_git)$(prompt_symbol)%{$reset_color%} ' |
Author
igorjs
commented
Mar 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment