Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions agnoster.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@
### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts

zmodload zsh/parameter

CURRENT_BG='NONE'
if [[ -z "$PRIMARY_FG" ]]; then
PRIMARY_FG=black
fi

# Characters
SEGMENT_SEPARATOR="\ue0b0"
PLUSMINUS="\u00b1"
BRANCH="\ue0a0"
DETACHED="\u27a6"
CROSS="\u2718"
LIGHTNING="\u26a1"
GEAR="\u2699"
SEGMENT_SEPARATOR=$'\ue0b0'
PLUSMINUS=$'\u00b1'
BRANCH=$'\ue0a0'
DETACHED=$'\u27a6'
CROSS=$'\u2718'
LIGHTNING=$'\u26a1'
GEAR=$'\u2699'

# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
Expand All @@ -47,22 +49,22 @@ prompt_segment() {
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
print -n "%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}"
PROMPT+="%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}"
else
print -n "%{$bg%}%{$fg%}"
PROMPT+="%{$bg%}%{$fg%}"
fi
CURRENT_BG=$1
[[ -n $3 ]] && print -n $3
[[ -n $3 ]] && PROMPT+="$3"
}

# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
PROMPT+="%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
print -n "%{%k%}"
PROMPT+="%{%k%}"
fi
print -n "%{%f%}"
PROMPT+="%{%f%}"
CURRENT_BG=''
}

Expand Down Expand Up @@ -99,7 +101,7 @@ prompt_git() {
ref="$DETACHED ${ref/.../}"
fi
prompt_segment $color $PRIMARY_FG
print -n " $ref"
PROMPT+=" $ref"
fi
}

Expand All @@ -117,7 +119,7 @@ prompt_status() {
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}$CROSS"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}$LIGHTNING"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}$GEAR"
[[ ${#jobstates} -ne 0 ]] && symbols+="%{%F{cyan}%}$GEAR"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this conflicts with the nohup filtering proposed in #61.


[[ -n "$symbols" ]] && prompt_segment $PRIMARY_FG default " $symbols "
}
Expand Down Expand Up @@ -145,7 +147,9 @@ prompt_agnoster_main() {

prompt_agnoster_precmd() {
vcs_info
PROMPT='%{%f%b%k%}$(prompt_agnoster_main) '
PROMPT='%{%f%b%k%}'
prompt_agnoster_main
PROMPT+=' '
}

prompt_agnoster_setup() {
Expand Down