Last active
October 25, 2020 03:12
-
-
Save 0xffan/78564985b29a245ebc79214b5eeb4047 to your computer and use it in GitHub Desktop.
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
# Sunrise theme for oh-my-zsh (https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/sunrise.zsh-theme) | |
# | |
# Color shortcuts | |
R=$fg_no_bold[red] | |
G=$fg_no_bold[green] | |
M=$fg_no_bold[magenta] | |
Y=$fg_no_bold[yellow] | |
B=$fg_no_bold[blue] | |
C=$fg_no_bold[cyan] | |
RESET=$reset_color | |
if [ "$USER" = "root" ]; then | |
PROMPTCOLOR="%{$R%}" USERNAMECOLOR="%{$R%}"; | |
else | |
PROMPTCOLOR="%{$M%}" USERNAMECOLOR="%{$M%}"; | |
fi | |
local return_code="%(?..%{$R%}%? ↵%{$RESET%})" | |
ZSH_THEME_GIT_PROMPT_PREFIX="%{$Y%}‹" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$Y%}›%{$RESET%} " | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$R%}*" | |
ZSH_THEME_GIT_PROMPT_CLEAN="" | |
ZSH_THEME_GIT_PROMPT_AHEAD="%{$B%}➔" | |
ZSH_THEME_GIT_STATUS_PREFIX=" " | |
# Customized git status prompt | |
CUSTOMIZED_GIT_STATUS_PROMPT_ADDED="%{$G%}+" | |
CUSTOMIZED_GIT_STATUS_PROMPT_MODIFIED="%{$G%}!" | |
CUSTOMIZED_GIT_STATUS_PROMPT_RENAMED="%{$G%}»" | |
CUSTOMIZED_GIT_STATUS_PROMPT_DELETED="%{$G%}✘" | |
CUSTOMIZED_GIT_STATUS_PROMPT_UNTRACKED="%{$R%}?" | |
CUSTOMIZED_GIT_STATUS_PROMPT_UNMERGED="%{$R%}=" | |
CUSTOMIZED_GIT_STATUS_PROMPT_AHEAD="%{$Y%}⇡" | |
CUSTOMIZED_GIT_STATUS_PROMPT_BEHIND="%{$Y%}⇣" | |
CUSTOMIZED_GIT_STATUS_PROMPT_DIVERGED="%{$Y%}⇕" | |
# Get the status of the working tree (copied and modified from git.zsh) | |
custom_git_prompt_status() { | |
INDEX=$(git status --porcelain -b 2> /dev/null) | |
git_status="" | |
# Check for untracked files | |
if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_UNTRACKED$git_status" | |
fi | |
# Check for staged files | |
if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_ADDED$git_status" | |
elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_ADDED$git_status" | |
elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_ADDED$git_status" | |
fi | |
# Check for modified files | |
if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_MODIFIED$git_status" | |
fi | |
# Check for renamed files | |
if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_RENAMED$git_status" | |
fi | |
# Check for deleted files | |
if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_DELETED$git_status" | |
elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_DELETED$git_status" | |
fi | |
# Check for unmerged files | |
if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_UNMERGED$git_status" | |
elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_UNMERGED$git_status" | |
elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_UNMERGED$git_status" | |
elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_UNMERGED$git_status" | |
fi | |
# Check whether branch is ahead | |
local is_ahead=false | |
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then | |
is_ahead=true | |
fi | |
# Check whether branch is behind | |
local is_behind=false | |
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then | |
is_behind=true | |
fi | |
# Check wheather branch has diverged | |
if [[ "$is_ahead" == true && "$is_behind" == true ]]; then | |
git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_DIVERGED$git_status" | |
else | |
[[ "$is_ahead" == true ]] && git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_AHEAD$git_status" | |
[[ "$is_behind" == true ]] && git_status="$CUSTOMIZED_GIT_STATUS_PROMPT_BEHIND$git_status" | |
fi | |
if $(echo -n "$STATUS" | grep '.*' &> /dev/null); then | |
git_status="$ZSH_THEME_GIT_STATUS_PREFIX$git_status" | |
fi | |
echo $git_status | |
} | |
# get the name of the branch we are on (copied and modified from git.zsh) | |
function custom_git_prompt() { | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$(custom_git_prompt_status)$ZSH_THEME_GIT_PROMPT_SUFFIX" | |
} | |
# %B sets bold text | |
PROMPT='$USERNAMECOLOR%B%n %{$C%}%2~ $(custom_git_prompt)%{$M%}%B»%b%{$RESET%} ' | |
RPS1="${return_code}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment