Created
May 26, 2022 08:41
-
-
Save JCash/a983aad0aa46752fb2c52d267461ffa6 to your computer and use it in GitHub Desktop.
Put in ~/.oh-my-zsh/custom/jcash.zsh-theme , Set ZSH_THEME="jcash" in ~ /.zshrc
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
eval fff='$FG[231]' | |
eval eee='$FG[252]' | |
eval ccc='$FG[007]' | |
eval gray='$FG[237]' | |
eval orange='$FG[214]' | |
eval lightorange='$FG[178]' | |
eval green='$FG[064]' | |
eval lightgreen='$FG[113]' | |
eval red='$FG[001]' | |
eval lightred='$FG[196]' | |
eval blue='$FG[032]' | |
eval lightblue='$FG[081]' | |
# ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$lightcolor%}[%{$color%}" | |
# ZSH_THEME_GIT_PROMPT_SUFFIX="" | |
# ZSH_THEME_GIT_PROMPT_DIRTY="%{$red%}+%{$lightcolor%}]%{$reset_color%} " | |
# ZSH_THEME_GIT_PROMPT_CLEAN="%{$lightcolor%}]%{$reset_color%} " | |
ZSH_THEME_GIT_PROMPT_PREFIX="" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="" | |
ZSH_THEME_GIT_PROMPT_DIRTY="" | |
ZSH_THEME_GIT_PROMPT_CLEAN="" | |
ZSH_THEME_SVN_PROMPT_PREFIX=$ZSH_THEME_GIT_PROMPT_PREFIX | |
ZSH_THEME_SVN_PROMPT_SUFFIX=$ZSH_THEME_GIT_PROMPT_SUFFIX | |
ZSH_THEME_SVN_PROMPT_DIRTY=$ZSH_THEME_GIT_PROMPT_DIRTY | |
ZSH_THEME_SVN_PROMPT_CLEAN=$ZSH_THEME_GIT_PROMPT_CLEAN | |
ZSH_THEME_HG_PROMPT_PREFIX=$ZSH_THEME_GIT_PROMPT_PREFIX | |
ZSH_THEME_HG_PROMPT_SUFFIX=$ZSH_THEME_GIT_PROMPT_SUFFIX | |
ZSH_THEME_HG_PROMPT_DIRTY=$ZSH_THEME_GIT_PROMPT_DIRTY | |
ZSH_THEME_HG_PROMPT_CLEAN=$ZSH_THEME_GIT_PROMPT_CLEAN | |
is_git_inside() { | |
if [[ "$(command git rev-parse --is-inside-work-tree 2> /dev/null)" == "true" ]]; then | |
echo 1 | |
else | |
echo 0 | |
fi | |
} | |
is_git_dirty() { | |
local STATUS='' | |
local FLAGS | |
FLAGS=('--porcelain') | |
if [[ "$(command git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then | |
if [[ $POST_1_7_2_GIT -gt 0 ]]; then | |
FLAGS+='--ignore-submodules=dirty' | |
fi | |
if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then | |
FLAGS+='--untracked-files=no' | |
fi | |
STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1) | |
fi | |
if [[ -n $STATUS ]]; then | |
echo 1 | |
else | |
echo 0 | |
fi | |
} | |
vcs_status() { | |
if [[ $(is_git_inside) == 1 ]]; then | |
git_prompt_info | |
elif [[ $(whence in_svn) != "" ]] && in_svn; then | |
svn_prompt_info | |
elif [[ $(whence in_hg) != "" ]] && in_hg; then | |
hg_prompt_info | |
else | |
echo "" | |
fi | |
} | |
# not in git | |
# untracked "Untracked files:" (lightred) | |
# modified "added to commit" "Changes not staged for commit:" (red) | |
# staged "Changes to be committed" (orange) | |
# committed "nothing to commit, working directory clean" (green) | |
# pushed "git diff origin/$(git name-rev --name-only HEAD)..HEAD --name-status 2>/dev/null" (blue) | |
# unknown (megenta) | |
function parse_git_status() { | |
local git_status="" | |
if [[ $(command git status | grep 'Changes not staged for commit:' 2> /dev/null) != "" ]]; then | |
git_status="modified" | |
elif [[ $(command git status | grep 'Untracked files:' 2> /dev/null) != "" ]]; then | |
git_status="untracked" | |
elif [[ $(command git status | grep 'Changes to be committed' 2> /dev/null) != "" ]]; then | |
git_status="staged" | |
elif [[ $(command git status | grep 'branch is up-to-date with' 2> /dev/null) != "" ]]; then | |
git_status="pushed" | |
fi | |
if [[ $git_status == "" ]]; then | |
local git_bad_origin="" | |
if [[ $(command git remote -v | grep 'origin' 2> /dev/null) == "" ]]; then | |
git_bad_origin="noorigin" | |
elif [[ $(command git log 2>&1 | grep 'bad default revision') != "" ]]; then | |
git_bad_origin="badorigin" | |
fi | |
if [[ $git_bad_origin == "badorigin" || $git_bad_origin == "noorigin" ]]; then | |
if [[ $(command git status | grep 'nothing to commit' 2> /dev/null) != "" ]]; then | |
git_status="committed" | |
fi | |
else | |
if [[ $(command git diff origin/$(git name-rev --name-only HEAD)..HEAD --name-status 2> /dev/null) == "" ]]; then | |
git_status="pushed" | |
elif [[ $(command git status | grep 'nothing to commit' 2> /dev/null) != "" ]]; then | |
git_status="committed" | |
fi | |
fi | |
if [[ $git_status == "" ]]; then | |
$git_status = $git_bad_origin | |
fi | |
fi | |
echo $git_status | |
} | |
label_vcs() { | |
if [[ $(vcs_status) == "" ]]; then | |
echo "" | |
else | |
local git_status=$(parse_git_status) | |
local label_color=$ccc | |
local label_lightcolor=$eee | |
# echo $git_status | |
if [[ $git_status == "untracked" ]]; then | |
label_color=$lightred | |
label_lightcolor=$red | |
elif [[ $git_status == "modified" ]]; then | |
label_color=$red | |
label_lightcolor=$lightred | |
elif [[ $git_status == "staged" ]]; then | |
label_color=$orange | |
label_lightcolor=$lightorange | |
elif [[ $git_status == "committed" ]]; then | |
label_color=$green | |
label_lightcolor=$lightgreen | |
elif [[ $git_status == "noorigin" ]]; then | |
label_color=$blue | |
label_lightcolor=$lightblue | |
elif [[ $git_status == "badorigin" ]]; then | |
label_color=$blue | |
label_lightcolor=$lightblue | |
elif [[ $git_status == "pushed" ]]; then | |
label_color=$blue | |
label_lightcolor=$lightblue | |
fi | |
echo "%{$reset_color%}%{$label_lightcolor%}[%{$label_color%}$(vcs_status)%{$label_lightcolor%}]%{$reset_color%}" | |
fi | |
} | |
label_cwd() { | |
echo "$ccc%{$fg[yellow]%}%3~ " | |
} | |
label_suffix() { | |
# exit code of last command | |
local ex=$1 | |
local color= | |
if [ "$_COMMAND_EXIT_CODE" -ne 0 ]; then | |
color="${red}" | |
fi | |
echo "%{$reset_color%}${color}$%{$reset_color%}" | |
} | |
print_prompt() { | |
export _COMMAND_EXIT_CODE=$? | |
echo "$(label_cwd)$(label_suffix) " | |
} | |
label_time() { | |
echo "%{$lightblue%} $(date +%H:%M:%S)" | |
} | |
PROMPT='$(print_prompt)' | |
RPROMPT='$(label_vcs)$(label_time)%{$reset_color%}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment