2013-11-09 03:26:25 +08:00
|
|
|
# oh-my-zsh Bureau Theme
|
|
|
|
|
|
|
|
### NVM
|
|
|
|
|
|
|
|
ZSH_THEME_NVM_PROMPT_PREFIX="%B⬡%b "
|
|
|
|
ZSH_THEME_NVM_PROMPT_SUFFIX=""
|
|
|
|
|
|
|
|
### Git [±master ▾●]
|
|
|
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_PREFIX="[%{$fg_bold[green]%}±%{$reset_color%}%{$fg_bold[white]%}"
|
|
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}]"
|
|
|
|
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}"
|
|
|
|
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[cyan]%}▴%{$reset_color%}"
|
|
|
|
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$reset_color%}"
|
|
|
|
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
|
|
|
|
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}"
|
|
|
|
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"
|
2023-05-24 20:32:26 +08:00
|
|
|
ZSH_THEME_GIT_PROMPT_STASHED="(%{$fg_bold[blue]%}✹%{$reset_color%})"
|
2013-11-09 03:26:25 +08:00
|
|
|
|
2022-02-08 00:44:05 +08:00
|
|
|
bureau_git_info () {
|
2021-12-27 07:38:58 +08:00
|
|
|
local ref
|
2013-11-09 03:26:25 +08:00
|
|
|
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
|
|
|
|
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
|
|
|
|
echo "${ref#refs/heads/}"
|
|
|
|
}
|
|
|
|
|
2016-04-05 02:39:10 +08:00
|
|
|
bureau_git_status() {
|
2022-01-04 00:05:48 +08:00
|
|
|
local result gitstatus
|
2022-02-05 04:08:03 +08:00
|
|
|
gitstatus="$(command git status --porcelain -b 2>/dev/null)"
|
2016-04-05 02:39:10 +08:00
|
|
|
|
|
|
|
# check status of files
|
2022-02-05 04:08:03 +08:00
|
|
|
local gitfiles="$(tail -n +2 <<< "$gitstatus")"
|
|
|
|
if [[ -n "$gitfiles" ]]; then
|
2022-02-08 00:44:05 +08:00
|
|
|
if [[ "$gitfiles" =~ $'(^|\n)[AMRD]. ' ]]; then
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_STAGED"
|
2014-04-26 06:44:02 +08:00
|
|
|
fi
|
2022-02-08 00:44:05 +08:00
|
|
|
if [[ "$gitfiles" =~ $'(^|\n).[MTD] ' ]]; then
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED"
|
2014-04-26 06:44:02 +08:00
|
|
|
fi
|
2022-02-08 00:44:05 +08:00
|
|
|
if [[ "$gitfiles" =~ $'(^|\n)\\?\\? ' ]]; then
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED"
|
2014-04-26 06:44:02 +08:00
|
|
|
fi
|
2022-02-08 00:44:05 +08:00
|
|
|
if [[ "$gitfiles" =~ $'(^|\n)UU ' ]]; then
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_UNMERGED"
|
2014-04-26 06:44:02 +08:00
|
|
|
fi
|
|
|
|
else
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_CLEAN"
|
2013-11-09 03:26:25 +08:00
|
|
|
fi
|
|
|
|
|
2016-04-05 02:39:10 +08:00
|
|
|
# check status of local repository
|
2022-02-05 04:08:03 +08:00
|
|
|
local gitbranch="$(head -n 1 <<< "$gitstatus")"
|
2022-02-08 00:44:05 +08:00
|
|
|
if [[ "$gitbranch" =~ '^## .*ahead' ]]; then
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_AHEAD"
|
2016-04-05 02:39:10 +08:00
|
|
|
fi
|
2022-02-08 00:44:05 +08:00
|
|
|
if [[ "$gitbranch" =~ '^## .*behind' ]]; then
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_BEHIND"
|
2016-04-05 02:39:10 +08:00
|
|
|
fi
|
2022-02-08 00:44:05 +08:00
|
|
|
if [[ "$gitbranch" =~ '^## .*diverged' ]]; then
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_DIVERGED"
|
2016-04-05 02:39:10 +08:00
|
|
|
fi
|
|
|
|
|
2022-02-08 00:44:05 +08:00
|
|
|
# check if there are stashed changes
|
|
|
|
if command git rev-parse --verify refs/stash &> /dev/null; then
|
2022-01-04 00:05:48 +08:00
|
|
|
result+="$ZSH_THEME_GIT_PROMPT_STASHED"
|
2016-04-05 02:39:10 +08:00
|
|
|
fi
|
|
|
|
|
2022-01-04 00:05:48 +08:00
|
|
|
echo $result
|
2013-11-09 03:26:25 +08:00
|
|
|
}
|
|
|
|
|
2021-12-27 07:38:58 +08:00
|
|
|
bureau_git_prompt() {
|
2023-05-22 18:49:10 +08:00
|
|
|
# ignore non git folders and hidden repos (adapted from lib/git.zsh)
|
|
|
|
if ! command git rev-parse --git-dir &> /dev/null \
|
|
|
|
|| [[ "$(command git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2022-02-08 00:44:05 +08:00
|
|
|
# check git information
|
|
|
|
local gitinfo=$(bureau_git_info)
|
|
|
|
if [[ -z "$gitinfo" ]]; then
|
2021-12-27 07:38:58 +08:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2022-02-08 00:44:05 +08:00
|
|
|
# quote % in git information
|
|
|
|
local output="${gitinfo:gs/%/%%}"
|
2021-12-27 07:38:58 +08:00
|
|
|
|
2022-02-08 00:44:05 +08:00
|
|
|
# check git status
|
|
|
|
local gitstatus=$(bureau_git_status)
|
2022-01-04 00:05:48 +08:00
|
|
|
if [[ -n "$gitstatus" ]]; then
|
2022-02-08 00:44:05 +08:00
|
|
|
output+=" $gitstatus"
|
2013-11-09 03:26:25 +08:00
|
|
|
fi
|
2021-12-27 07:38:58 +08:00
|
|
|
|
2022-02-08 00:44:05 +08:00
|
|
|
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${output}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
2013-11-09 03:26:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_PATH="%{$fg_bold[white]%}%~%{$reset_color%}"
|
|
|
|
|
2014-01-03 21:43:31 +08:00
|
|
|
if [[ $EUID -eq 0 ]]; then
|
2013-11-09 03:26:25 +08:00
|
|
|
_USERNAME="%{$fg_bold[red]%}%n"
|
|
|
|
_LIBERTY="%{$fg[red]%}#"
|
|
|
|
else
|
|
|
|
_USERNAME="%{$fg_bold[white]%}%n"
|
|
|
|
_LIBERTY="%{$fg[green]%}$"
|
|
|
|
fi
|
|
|
|
_USERNAME="$_USERNAME%{$reset_color%}@%m"
|
|
|
|
_LIBERTY="$_LIBERTY%{$reset_color%}"
|
|
|
|
|
|
|
|
|
|
|
|
get_space () {
|
|
|
|
local STR=$1$2
|
|
|
|
local zero='%([BSUbfksu]|([FB]|){*})'
|
2014-04-26 06:44:02 +08:00
|
|
|
local LENGTH=${#${(S%%)STR//$~zero/}}
|
2022-02-08 00:52:57 +08:00
|
|
|
local SPACES=$(( COLUMNS - LENGTH - ${ZLE_RPROMPT_INDENT:-1} ))
|
2014-04-26 06:44:02 +08:00
|
|
|
|
2022-02-08 00:52:57 +08:00
|
|
|
(( SPACES > 0 )) || return
|
|
|
|
printf ' %.0s' {1..$SPACES}
|
2013-11-09 03:26:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_1LEFT="$_USERNAME $_PATH"
|
2022-02-08 00:52:57 +08:00
|
|
|
_1RIGHT="[%*]"
|
2013-11-09 03:26:25 +08:00
|
|
|
|
|
|
|
bureau_precmd () {
|
|
|
|
_1SPACES=`get_space $_1LEFT $_1RIGHT`
|
2014-04-26 06:44:02 +08:00
|
|
|
print
|
2014-03-11 07:36:51 +08:00
|
|
|
print -rP "$_1LEFT$_1SPACES$_1RIGHT"
|
2013-11-09 03:26:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
setopt prompt_subst
|
2014-03-11 07:36:51 +08:00
|
|
|
PROMPT='> $_LIBERTY '
|
2013-11-09 03:26:25 +08:00
|
|
|
RPROMPT='$(nvm_prompt_info) $(bureau_git_prompt)'
|
|
|
|
|
|
|
|
autoload -U add-zsh-hook
|
|
|
|
add-zsh-hook precmd bureau_precmd
|