mirror of
https://github.com/ChesterYue/ohmyzsh-theme-passion.git
synced 2026-07-21 20:11:03 +00:00
update
This commit is contained in:
parent
491f39820b
commit
d7ad045daa
1 changed files with 135 additions and 28 deletions
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
# gdate for macOS
|
||||
# REF: https://apple.stackexchange.com/questions/135742/time-in-milliseconds-since-epoch-in-the-terminal
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
|
|
@ -60,25 +59,141 @@ function directory() {
|
|||
|
||||
|
||||
# git
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_no_bold[blue]%}git(%{$fg_no_bold[red]%}";
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} ";
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_no_bold[blue]%}) %{$fg_no_bold[red]%}⬢";#⬣⎔⬢⬣⇵⇅
|
||||
# ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_no_bold[blue]%}) 🔥";
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_no_bold[blue]%}) %{$fg_no_bold[green]%}⬡";#⬡
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_no_bold[blue]%}❮%{$fg_no_bold[red]%}";
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}";
|
||||
ZSH_THEME_GIT_PROMPT_END_SUFFIX="%{$fg_no_bold[blue]%}❯%{$reset_color%}";
|
||||
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}"
|
||||
|
||||
# ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED=true;
|
||||
# ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE="%{$fg_no_bold[red]%}⇡"
|
||||
# ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="%{$fg_no_bold[red]%}⇣"
|
||||
ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX="$FG[005]⇡"
|
||||
ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX=""
|
||||
ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX="%{$reset_color%}"
|
||||
ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX="$FG[005]⇣"
|
||||
ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX=""
|
||||
ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX="%{$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%}"
|
||||
|
||||
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[red]%}!%{$reset_color%}"
|
||||
|
||||
|
||||
function __git_branch() {
|
||||
local ref
|
||||
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
|
||||
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
|
||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref#refs/heads/}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
function vscode_git_status() {
|
||||
[[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return
|
||||
|
||||
# Maps a git status prefix to an internal constant
|
||||
# This cannot use the prompt constants, as they may be empty
|
||||
local -A prefix_constant_map
|
||||
prefix_constant_map=(
|
||||
'\?\? ' 'UNTRACKED'
|
||||
'[MTARC][MTD] ' 'STAGEDUNSTAGED'
|
||||
'[MTARC] ' 'STAGED'
|
||||
'D ' 'STAGED'
|
||||
' [AMD] ' 'UNSTAGED'
|
||||
'[DAU][DAU] ' 'UNMERGED'
|
||||
'ahead' 'AHEAD'
|
||||
'behind' 'BEHIND'
|
||||
'diverged' 'DIVERGED'
|
||||
'stashed' 'STASHED'
|
||||
)
|
||||
|
||||
# Maps the internal constant to the prompt theme
|
||||
local -A constant_prompt_map
|
||||
constant_prompt_map=(
|
||||
'UNTRACKED' "$ZSH_THEME_GIT_PROMPT_UNTRACKED"
|
||||
'ADDED' "$ZSH_THEME_GIT_PROMPT_ADDED"
|
||||
'MODIFIED' "$ZSH_THEME_GIT_PROMPT_MODIFIED"
|
||||
'RENAMED' "$ZSH_THEME_GIT_PROMPT_RENAMED"
|
||||
'DELETED' "$ZSH_THEME_GIT_PROMPT_DELETED"
|
||||
'UNMERGED' "$ZSH_THEME_GIT_PROMPT_UNMERGED"
|
||||
'AHEAD' "$(git_commits_ahead)"
|
||||
'BEHIND' "$(git_commits_behind)"
|
||||
'DIVERGED' "$ZSH_THEME_GIT_PROMPT_DIVERGED"
|
||||
'STASHED' "$ZSH_THEME_GIT_PROMPT_STASHED"
|
||||
'STAGED' "$ZSH_THEME_GIT_PROMPT_STAGED"
|
||||
'UNSTAGED' "$ZSH_THEME_GIT_PROMPT_UNSTAGED"
|
||||
'STAGEDUNSTAGED' "${ZSH_THEME_GIT_PROMPT_UNSTAGED}${ZSH_THEME_GIT_PROMPT_STAGED}"
|
||||
)
|
||||
|
||||
# The order that the prompt displays should be added to the prompt
|
||||
local status_constants
|
||||
status_constants=(
|
||||
UNTRACKED ADDED MODIFIED RENAMED DELETED
|
||||
STASHED UNMERGED AHEAD BEHIND DIVERGED STAGED UNSTAGED STAGEDUNSTAGED
|
||||
)
|
||||
|
||||
local status_text
|
||||
status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)"
|
||||
|
||||
# Don't continue on a catastrophic failure
|
||||
if [[ $? -eq 128 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# A lookup table of each git status encountered
|
||||
local -A statuses_seen
|
||||
|
||||
if __git_prompt_git rev-parse --verify refs/stash &>/dev/null; then
|
||||
statuses_seen[STASHED]=1
|
||||
fi
|
||||
|
||||
local status_lines
|
||||
status_lines=("${(@f)${status_text}}")
|
||||
|
||||
# If the tracking line exists, get and parse it
|
||||
if [[ "$status_lines[1]" =~ "^## [^ ]+ \[(.*)\]" ]]; then
|
||||
local branch_statuses
|
||||
branch_statuses=("${(@s/,/)match}")
|
||||
for branch_status in $branch_statuses; do
|
||||
if [[ ! $branch_status =~ "(behind|diverged|ahead) ([0-9]+)?" ]]; then
|
||||
continue
|
||||
fi
|
||||
local last_parsed_status=$prefix_constant_map[$match[1]]
|
||||
statuses_seen[$last_parsed_status]=$match[2]
|
||||
done
|
||||
fi
|
||||
|
||||
# For each status prefix, do a regex comparison
|
||||
for status_prefix in ${(k)prefix_constant_map}; do
|
||||
local status_constant="${prefix_constant_map[$status_prefix]}"
|
||||
local status_regex=$'(^|\n)'"$status_prefix"
|
||||
|
||||
if [[ "$status_text" =~ $status_regex ]]; then
|
||||
statuses_seen[$status_constant]=1
|
||||
fi
|
||||
done
|
||||
|
||||
# Display the seen statuses in the order specified
|
||||
local status_prompt
|
||||
for status_constant in $status_constants; do
|
||||
if (( ${+statuses_seen[$status_constant]} )); then
|
||||
local next_display=$constant_prompt_map[$status_constant]
|
||||
status_prompt="$next_display$status_prompt"
|
||||
fi
|
||||
done
|
||||
|
||||
echo $status_prompt
|
||||
}
|
||||
|
||||
function update_git_status() {
|
||||
GIT_STATUS=$(git_prompt_info);
|
||||
if __git_prompt_git rev-parse --git-dir &>/dev/null; then
|
||||
GIT_STATUS=$(__git_branch);
|
||||
local git_status="$(vscode_git_status)"
|
||||
if [[ $git_status != "" ]]; then
|
||||
GIT_STATUS+=" ${git_status}";
|
||||
fi
|
||||
GIT_STATUS+=${ZSH_THEME_GIT_PROMPT_END_SUFFIX};
|
||||
fi
|
||||
}
|
||||
|
||||
function git_status() {
|
||||
update_git_status;
|
||||
echo "${GIT_STATUS}"
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +306,7 @@ current_time_millis() {
|
|||
|
||||
# command execute after
|
||||
# REF: http://zsh.sourceforge.net/Doc/Release/Functions.html
|
||||
precmd() {
|
||||
dash_passion_precmd() {
|
||||
# last_cmd
|
||||
local last_cmd_return_code=$?;
|
||||
local last_cmd_result=true;
|
||||
|
|
@ -203,7 +318,7 @@ precmd() {
|
|||
fi
|
||||
|
||||
# update_git_status
|
||||
update_git_status;
|
||||
update_git_status
|
||||
|
||||
# update_command_status
|
||||
update_command_status $last_cmd_result;
|
||||
|
|
@ -213,14 +328,8 @@ precmd() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
# set option
|
||||
setopt PROMPT_SUBST;
|
||||
|
||||
|
||||
# timer
|
||||
#REF: https://stackoverflow.com/questions/26526175/zsh-menu-completion-causes-problems-after-zle-reset-prompt
|
||||
TMOUT=1;
|
||||
|
||||
TRAPALRM() {
|
||||
# $(git_prompt_info) cost too much time which will raise stutters when inputting. so we need to disable it in this occurence.
|
||||
# if [ "$WIDGET" != "expand-or-complete" ] && [ "$WIDGET" != "self-insert" ] && [ "$WIDGET" != "backward-delete-char" ]; then
|
||||
|
|
@ -231,11 +340,9 @@ TRAPALRM() {
|
|||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
# prompt
|
||||
# PROMPT='$(real_time) $(login_info) $(directory) $(git_status)$(command_status) ';
|
||||
# PROMPT='$(real_time) $(directory) $(git_status)$(command_status) ';
|
||||
PROMPT='$(real_time) $(directory) $(git_status)$(git_commits_ahead)$(git_commits_behind) $(command_status) ';
|
||||
# RPROMPT='%{$FG[242]%}%n@%m${color_reset}';
|
||||
setopt prompt_subst
|
||||
PROMPT='$(real_time) $(directory) $(git_status) $(command_status) ';
|
||||
RPROMPT='%{$FG[242]%}%n@%m $(battery_pct_prompt)${color_reset}';
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
add-zsh-hook precmd dash_passion_precmd
|
||||
Loading…
Add table
Reference in a new issue