diff options
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index cef789c2..e2f3b4fd 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -124,6 +124,7 @@ CURRENT_BG='NONE' # * $3: Background color # * $4: Foreground color # * $5: The segment content +# * $6: An identifying icon (must be a key of the icons array) # The latter three can be omitted, set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " " left_prompt_segment() { @@ -146,7 +147,7 @@ left_prompt_segment() { echo -n "%{$bg%F{$CURRENT_BG}%}" if [[ $joined == false ]]; then # Middle segment - echo -n "$(print_icon 'LEFT_SEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "$(print_icon 'LEFT_SEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi elif isSameColor "$CURRENT_BG" "$3"; then # Middle segment with same color as previous segment @@ -157,14 +158,27 @@ left_prompt_segment() { [[ -n "$4" ]] && complement="$4" || complement=$DEFAULT_COLOR echo -n "%{$bg%F{$complement}%}" if [[ $joined == false ]]; then - echo -n "$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "$(print_icon 'LEFT_SUBSEGMENT_SEPARATOR')$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" fi else # First segment - echo -n "%{$bg%}%{$fg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + echo -n "%{$bg%}$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS" + fi + + local visual_identifier + if [[ -n $6 ]]; then + visual_identifier="$(print_icon $6)" + if [[ -n "$visual_identifier" ]]; then + # Allow users to overwrite the color for the visual identifier only. + local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR + set_default $visual_identifier_color_variable $4 + visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" + # Add an whitespace if we print more than just the visual identifier + [[ -n "$5" ]] && visual_identifier="$visual_identifier " + fi fi - [[ -n "$5" ]] && echo -n "${5}${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" + [[ -n "$5" ]] && echo -n "${visual_identifier}%{$fg%}${5}${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}" CURRENT_BG=$3 } @@ -190,6 +204,7 @@ CURRENT_RIGHT_BG='NONE' # * $3: Background color # * $4: Foreground color # * $5: The segment content +# * $6: An identifying icon (must be a key of the icons array) # No ending for the right prompt segment is needed (unlike the left prompt, above). set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " " right_prompt_segment() { @@ -222,13 +237,27 @@ right_prompt_segment() { echo -n "%F{$3}$(print_icon 'RIGHT_SEGMENT_SEPARATOR')%f" fi fi + + local visual_identifier + if [[ -n "$6" ]]; then + visual_identifier="$(print_icon $6)" + if [[ -n "$visual_identifier" ]]; then + # Allow users to overwrite the color for the visual identifier only. + local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR + set_default $visual_identifier_color_variable $4 + visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" + # Add an whitespace if we print more than just the visual identifier + [[ -n "$5" ]] && visual_identifier=" $visual_identifier" + fi + fi + echo -n "%{$bg%}%{$fg%}" - # Print whitespace only if segment is not joined + # 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}" # Print segment content - [[ -n "$5" ]] && echo -n "${5}${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}%f" + [[ -n "$5" ]] && echo -n "${5}${visual_identifier}${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}%f" CURRENT_RIGHT_BG=$3 } @@ -247,7 +276,7 @@ prompt_aws() { local aws_profile="$AWS_DEFAULT_PROFILE" if [[ -n "$aws_profile" ]]; then - "$1_prompt_segment" "$0" "$2" red white "$(print_icon 'AWS_ICON') $aws_profile" + "$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON' fi } @@ -349,15 +378,15 @@ prompt_battery() { fi # prepare string - local message="$(print_icon 'BATTERY_ICON')" + local message # Default behavior: Be verbose! set_default POWERLEVEL9K_BATTERY_VERBOSE true if [[ "$POWERLEVEL9K_BATTERY_VERBOSE" == true ]]; then - message="$message $bat_percent%%$remain" + message="$bat_percent%%$remain" fi # display prompt_segment - [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" + [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON' } # Context: user@hostname (who am I and where am I) @@ -394,12 +423,10 @@ prompt_dir() { local current_icon='' if [[ $(print -P "%~") == '~'* ]]; then - current_icon=$(print_icon 'HOME_ICON') + "$1_prompt_segment" "$0_HOME" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_ICON' else - current_icon=$(print_icon 'FOLDER_ICON') + "$1_prompt_segment" "$0_DEFAULT" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'FOLDER_ICON' fi - - "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$current_icon$current_path" } # GO-prompt @@ -454,7 +481,7 @@ prompt_ip() { fi fi - "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$(print_icon 'NETWORK_ICON') $ip" + "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'NETWORK_ICON' } prompt_load() { @@ -478,7 +505,7 @@ prompt_load() { FUNCTION_SUFFIX="_NORMAL" fi - "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$2" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$(print_icon 'LOAD_ICON') $load_avg_5min" + "$1_prompt_segment" "$0$FUNCTION_SUFFIX" "$2" "$BACKGROUND_COLOR" "$DEFAULT_COLOR" "$load_avg_5min" 'LOAD_ICON' } # Node version @@ -486,7 +513,7 @@ prompt_node_version() { local node_version=$(node -v 2>/dev/null) [[ -z "${node_version}" ]] && return - "$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1} $(print_icon 'NODE_ICON')" + "$1_prompt_segment" "$0" "$2" "green" "white" "${node_version:1}" 'NODE_ICON' } # print a little OS icon @@ -556,13 +583,13 @@ prompt_nvm() { [[ -z "${node_version}" ]] && return [[ "$node_version" =~ "$nvm_default" ]] && return - $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1} $(print_icon 'NODE_ICON')" + $1_prompt_segment "$0" "$2" "green" "011" "${node_version:1}" 'NODE_ICON' } # rbenv information prompt_rbenv() { if [[ -n "$RBENV_VERSION" ]]; then - "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$RBENV_VERSION" + "$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" "$RBENV_VERSION" 'RUBY_ICON' fi } @@ -601,7 +628,7 @@ prompt_rvm() { local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') if [[ -n "$version$gemset" ]]; then - "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version$gemset $(print_icon 'RUBY_ICON') " + "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version$gemset" 'RUBY_ICON' fi } @@ -671,7 +698,7 @@ prompt_todo() { if $(hash todo.sh 2>&-); then count=$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+) tasks shown" | awk '{ print $4 }') if [[ "$count" = <-> ]]; then - "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" "$(print_icon 'TODO_ICON') $count" + "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" "$count" 'TODO_ICON' fi fi } @@ -819,7 +846,7 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down else - RPROMPT_PREFIX='' + RPROMPT_PREFIX='' RPROMPT_SUFFIX='' fi else @@ -875,7 +902,7 @@ powerlevel9k_init() { print_deprecation_warning deprecated_segments setopt prompt_subst - + setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS setopt PROMPT_CR PROMPT_PERCENT PROMPT_SUBST MULTIBYTE |