Skip to content

Instantly share code, notes, and snippets.

@lixingcong
Last active October 12, 2023 02:45
Show Gist options
  • Save lixingcong/5e57841f61a333b835ed4149eaeb23c1 to your computer and use it in GitHub Desktop.
Save lixingcong/5e57841f61a333b835ed4149eaeb23c1 to your computer and use it in GitHub Desktop.
zsh theme: muse-lxc
#!/usr/bin/env zsh
# update: 2023-10-12
# source
# https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/muse.zsh-theme
# search all git colors
# grep -o "ZSH_THEME_GIT_[A-Z_]\+" ~/.oh-my-zsh/lib/git.zsh | sort | uniq
# bash color list
# https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
# print 256 colors on terminal
# https://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal
setopt promptsubst
autoload -U add-zsh-hook
local return_code="%(?.%{$FG[119]%}✔.%{$FG[202]%}✘%?)%{$reset_color%}"
local current_path="%{$FG[117]%}%~%{$reset_color%}"
# modify from .oh-my-zsh/lib/git.zsh
function xgit_remote_status() {
local remote ahead behind git_remote_status git_remote_status_detailed
remote=${$(__git_prompt_git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
if [[ -n ${remote} ]]; then
ahead=$(__git_prompt_git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
behind=$(__git_prompt_git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
if [[ $ahead -eq 0 ]] && [[ $behind -eq 0 ]]; then
git_remote_status="$ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE"
elif [[ $ahead -gt 0 ]] && [[ $behind -eq 0 ]]; then
git_remote_status="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}"
elif [[ $behind -gt 0 ]] && [[ $ahead -eq 0 ]]; then
git_remote_status="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}"
elif [[ $ahead -gt 0 ]] && [[ $behind -gt 0 ]]; then
git_remote_status="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}"
fi
echo "$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX$git_remote_status$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX"
fi
}
function xgit_prompt_info() {
if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
local ref
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
local tagString=`git describe --abbrev=0 --tags 2>/dev/null`
if [ ! -z $tagString ]; then
tagString=" $FG[177]$tagString"
fi
local remoteString=$(xgit_remote_status)
if [ ! -z $remoteString ]; then
remoteString=" $remoteString"
fi
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$remoteString$tagString$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
}
local PROMPT_LINE_1='${return_code} ${current_path} $(xgit_prompt_info)$(git_prompt_status) $(virtualenv_prompt_info)'
local PROMPT_LINE_2='%{$reset_color%}\$ '
PROMPT="${PROMPT_LINE_1}
${PROMPT_LINE_2}"
GIT_PROMPT_INFO=$FG[033]
ZSH_THEME_GIT_PROMPT_PREFIX="%{$GIT_PROMPT_INFO%}("
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$GIT_PROMPT_INFO%})"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$FG[009]%}*"
#ZSH_THEME_GIT_PROMPT_CLEAN="%{$FG[040]%}✔"
ZSH_THEME_GIT_PROMPT_ADDED="%{$FG[010]%}a%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$FG[166]%}m%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DELETED="%{$FG[200]%}d%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_RENAMED="%{$FG[220]%}r%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$FG[051]%}u%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$FG[226]%}?%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STASHED="%{$FG[214]%}s%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="↓"
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE="↑"
ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="↕"
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR="%{$reset_color%}"
ZSH_THEME_VIRTUALENV_PREFIX="["
ZSH_THEME_VIRTUALENV_SUFFIX="]"
@lixingcong
Copy link
Author

lixingcong commented Sep 17, 2016

太花哨的主题卡,不流畅,选用一个简单的主题

注意终端字体要设置成Dejavu Sans Mono,否则绿色的打勾号显示异常

Screenshot_20231012_104410

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