diff options
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index edd16582..c01c9a9d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -147,7 +147,7 @@ left_prompt_segment() { local joined=$2 if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$3" "$CURRENT_BG"; then - echo -n "%{$bg%F{$CURRENT_BG}%}" + echo -n "$bg%F{$CURRENT_BG}" if [[ $joined == false ]]; then # Middle segment echo -n "$(print_icon 'LEFT_SEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" @@ -159,13 +159,13 @@ left_prompt_segment() { # enough contrast. local complement [[ -n "$4" ]] && complement="$4" || complement=$DEFAULT_COLOR - echo -n "%{$bg%F{$complement}%}" + echo -n "$bg%F{$complement}" if [[ $joined == false ]]; then echo -n "$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi else # First segment - echo -n "%{$bg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "${bg}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi local visual_identifier @@ -184,7 +184,7 @@ left_prompt_segment() { # Print the visual identifier echo -n "${visual_identifier}" # Print the content of the segment, if there is any - [[ -n "$5" ]] && echo -n "%{$fg%}${5}" + [[ -n "$5" ]] && echo -n "${fg}${5}" echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" CURRENT_BG=$3 @@ -193,11 +193,11 @@ left_prompt_segment() { # End the left prompt, closes the final segment. left_prompt_end() { if [[ -n $CURRENT_BG ]]; then - echo -n "%{%k%F{$CURRENT_BG}%}$(print_icon 'LEFT_SEGMENT_SEPARATOR')" + echo -n "%k%F{$CURRENT_BG}$(print_icon 'LEFT_SEGMENT_SEPARATOR')" else echo -n "%k" fi - echo -n "%{%f%}$(print_icon 'LEFT_SEGMENT_END_SEPARATOR')" + echo -n "%f$(print_icon 'LEFT_SEGMENT_END_SEPARATOR')" CURRENT_BG='' } @@ -258,7 +258,7 @@ right_prompt_segment() { fi fi - echo -n "%{$bg%}%{$fg%}" + echo -n "${bg}${fg}" # Print whitespace only if segment is not joined or first right segment [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]] && echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}" @@ -289,14 +289,6 @@ prompt_aws() { fi } -# The 'custom` prompt provides a way for users to invoke commands and display -# the output in a segment. -prompt_custom() { - local command=POWERLEVEL9K_CUSTOM_$3:u - - "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" -} - # Segment to indicate background jobs with an icon. prompt_background_jobs() { if [[ $(jobs -l | wc -l) -gt 0 ]]; then @@ -407,6 +399,14 @@ prompt_context() { fi } +# The 'custom` prompt provides a way for users to invoke commands and display +# the output in a segment. +prompt_custom() { + local command=POWERLEVEL9K_CUSTOM_$3:u + + "$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})" +} + # Dir: current working directory prompt_dir() { local current_path='%~' @@ -492,6 +492,14 @@ prompt_ip() { } prompt_load() { + # The load segment can have three different states + local current_state="unknown" + typeset -AH load_states + load_states=( + 'critical' 'red' + 'warning' 'yellow' + 'normal' 'green' + ) if [[ "$OS" == "OSX" ]]; then load_avg_5min=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 1) else @@ -502,17 +510,14 @@ prompt_load() { load_avg_5min=${load_avg_5min//,/.} if [[ "$load_avg_5min" -gt 10 ]]; then - BACKGROUND_COLOR="red" - FUNCTION_SUFFIX="_CRITICAL" + current_state="critical" elif [[ "$load_avg_5min" -gt 3 ]]; then - BACKGROUND_COLOR="yellow" - FUNCTION_SUFFIX="_WARNING" + current_state="warning" else - BACKGROUND_COLOR="green" - FUNCTION_SUFFIX="_NORMAL" + current_state="normal" fi - "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$2" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' + "$1_prompt_segment" "${0}${current_state}" "$2" "${load_states[$current_state]}" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' } # Node version @@ -639,7 +644,7 @@ prompt_rvm() { fi } -# Status: (return code, root status, background jobs) +# Status: return code if verbose, otherwise just an icon if an error occurred set_default POWERLEVEL9K_STATUS_VERBOSE true prompt_status() { if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then @@ -843,7 +848,7 @@ powerlevel9k_prepare_prompts() { RETVAL=$? if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then - PROMPT="$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%{%f%b%k%}$(build_left_prompt) + PROMPT="$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt) $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" if [[ "$POWERLEVEL9K_RPROMPT_ON_NEWLINE" != true ]]; then # The right prompt should be on the same line as the first line of the left @@ -859,13 +864,13 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" RPROMPT_SUFFIX='' fi else - PROMPT="%{%f%b%k%}$(build_left_prompt)" + PROMPT="%f%b%k$(build_left_prompt)" RPROMPT_PREFIX='' RPROMPT_SUFFIX='' fi if [[ "$POWERLEVEL9K_DISABLE_RPROMPT" != true ]]; then - RPROMPT="$RPROMPT_PREFIX%{%f%b%k%}$(build_right_prompt)%{$reset_color%}$RPROMPT_SUFFIX" + RPROMPT="$RPROMPT_PREFIX%f%b%k$(build_right_prompt)%{$reset_color%}$RPROMPT_SUFFIX" fi } |