From 01e66aab67823c73abf9461f5a675ab63632d5e6 Mon Sep 17 00:00:00 2001 From: romkatv Date: Fri, 26 Jul 2019 15:35:46 +0200 Subject: [PATCH 01/11] add a few extra states and parameters to make it possible to configure decent `status` --- config/p10k-lean.zsh | 23 ++++++++++- internal/p10k.zsh | 90 ++++++++++++++++++++++---------------------- 2 files changed, 65 insertions(+), 48 deletions(-) diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index 53633ede..dfe03de4 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -306,10 +306,29 @@ fi typeset -g POWERLEVEL9K_VCS_STAGED_ICON=$'%{\b+%}' ##########################[ status: exit code of the last command ]########################### - # Don't show status on success. Prompt symbol (prompt_char) indicates success with green color. + # Enable OK_PIPE, ERROR_PIPE and ERROR_SIGNAL status states to allow us to enable, disable and + # style them independently from the regular OK and ERROR state. + typeset -g POWERLEVEL9K_STATUS_EXTENDED_STATES=true + # Don't show status on success. prompt_char already indicates success with green color. typeset -g POWERLEVEL9K_STATUS_OK=false - # Error status color. + # Don't show status when it's just an error code (e.g., '1'). prompt_char already indicates errors + # with red color and error codes aren't interesting enough to waste prompt real estate on them. + typeset -g POWERLEVEL9K_STATUS_ERROR=false typeset -g POWERLEVEL9K_STATUS_ERROR_FOREGROUND=9 + # Show status when the last command was terminated by a signal. + typeset -g POWERLEVEL9K_STATUS_ERROR_SIGNAL=true + typeset -g POWERLEVEL9K_STATUS_ERROR_SIGNAL_FOREGROUND=9 + # Use terse signal names: "INT" instead of "SIGINT(2)". + typeset -g POWERLEVEL9K_STATUS_VERBOSE_SIGNAME=false + # Show status when a pipe command fails and the overall exit status is non-zero. It may look + # like this: 0|1. prompt_char is red in this case. + typeset -g POWERLEVEL9K_STATUS_ERROR_PIPE=true + typeset -g POWERLEVEL9K_STATUS_ERROR_PIPE_FOREGROUND=9 + # Show status when a pipe command fails and the overall exit status is zero. It may look + # like this: 1|0. prompt_char is green in this case. + typeset -g POWERLEVEL9K_STATUS_OK_PIPE=true + typeset -g POWERLEVEL9K_STATUS_OK_PIPE_FOREGROUND=9 + # Don't show status unless the last command was terminated by a signal. Your prompt symbol # (prompt_char) indicates error by turning red. Error codes aren't usually interesting but # signals are. This shows signals as "INT", "ABORT", "KILL", etc. You can remove this parameter diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 77aa1e97..73c7fc68 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -1190,7 +1190,7 @@ prompt_context() { ################################################################ # User: user (who am I) prompt_user() { - if ! _p9k_cache_get $0 $1 $2; then + if ! _p9k_cache_get $0; then local user=$(whoami) if [[ $_POWERLEVEL9K_ALWAYS_SHOW_USER == 0 && $user == $DEFAULT_USER ]]; then _p9k_cache_set true @@ -1468,7 +1468,7 @@ prompt_dir() { [[ $_POWERLEVEL9K_DIR_SHOW_WRITABLE == 1 && ! -w $PWD ]] local w=$? - if ! _p9k_cache_get $0 $2 $PWD $w $fake_first "${parts[@]}"; then + if ! _p9k_cache_get $0 $PWD $w $fake_first "${parts[@]}"; then local state=$0 local icon='' if (( ! w )); then @@ -2061,57 +2061,36 @@ prompt_ssh() { fi } -_p9k_exit_code_or_status() { - local ec=$1 - if (( _POWERLEVEL9K_STATUS_HIDE_SIGNAME || ec <= 128 )); then - _p9k_ret=$ec - else - _p9k_ret="SIG${signals[$((ec - 127))]}($((ec - 128)))" - fi -} - ################################################################ # Status: When an error occur, return the error code, or a cross icon if option is set # Display an ok icon when no error occur, or hide the segment if option is set to false prompt_status() { - if ! _p9k_cache_get "$0" "$2" "$__p9k_exit_code" "${(@)__p9k_pipe_exit_codes}"; then - local ec_text - local ec_sum - local ec - - if (( _POWERLEVEL9K_STATUS_SHOW_PIPESTATUS )); then - if (( $#__p9k_pipe_exit_codes > 1 )); then - ec_sum=${__p9k_pipe_exit_codes[1]} - _p9k_exit_code_or_status "${__p9k_pipe_exit_codes[1]}" - - else - ec_sum=${__p9k_exit_code} - _p9k_exit_code_or_status "${__p9k_exit_code}" + if ! _p9k_cache_get $0 $__p9k_exit_code $__p9k_pipe_exit_codes; then + (( __p9k_exit_code )) && local state=ERROR || local state=OK + if (( _POWERLEVEL9K_STATUS_EXTENDED_STATES )); then + if (( __p9k_exit_code )); then + if (( $#__p9k_pipe_exit_codes > 1 )); then + state+=_PIPE + elif (( __p9k_exit_code > 128 )); then + state+=_SIGNAL + fi + elif [[ "$__p9k_pipe_exit_codes" == *[1-9]* ]]; then + state+=_PIPE fi - ec_text=$_p9k_ret - for ec in "${(@)__p9k_pipe_exit_codes[2,-1]}"; do - (( ec_sum += ec )) - _p9k_exit_code_or_status "$ec" - ec_text+="|$_p9k_ret" - done - else - ec_sum=${__p9k_exit_code} - # We use __p9k_exit_code instead of the right-most __p9k_pipe_exit_codes item because - # PIPE_FAIL may be set. - _p9k_exit_code_or_status "${__p9k_exit_code}" - ec_text=$_p9k_ret fi - - if (( ec_sum > 0 )); then - if (( !_POWERLEVEL9K_STATUS_CROSS && _POWERLEVEL9K_STATUS_VERBOSE )); then - _p9k_cache_val=("$0_ERROR" red yellow1 CARRIAGE_RETURN_ICON 0 '' "$ec_text") - else - _p9k_cache_val=("$0_ERROR" "$_p9k_color1" red FAIL_ICON 0 '' '') + _p9k_cache_val=(:) + if (( _POWERLEVEL9K_STATUS_$state )); then + local text=${(j:|:)${(@)__p9k_pipe_exit_codes:/(#b)(*)/$_p9k_exitcode2str[$match[1]+1]}} + if (( __p9k_exit_code )); then + if (( !_POWERLEVEL9K_STATUS_CROSS && _POWERLEVEL9K_STATUS_VERBOSE )); then + _p9k_cache_val=($0_$state red yellow1 CARRIAGE_RETURN_ICON 0 '' "$text") + else + _p9k_cache_val=($0_$state $_p9k_color1 red FAIL_ICON 0 '' '') + fi + elif (( _POWERLEVEL9K_STATUS_VERBOSE || _POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE )); then + [[ $state == OK ]] && text='' + _p9k_cache_val=($0_$state "$_p9k_color1" green OK_ICON 0 '' "$text") fi - elif (( _POWERLEVEL9K_STATUS_OK && (_POWERLEVEL9K_STATUS_VERBOSE || _POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE) )); then - _p9k_cache_val=("$0_OK" "$_p9k_color1" green OK_ICON 0 '' '') - else - return fi if (( $#__p9k_pipe_exit_codes < 3 )); then _p9k_cache_set "${(@)_p9k_cache_val}" @@ -3168,6 +3147,7 @@ p9k_refresh_prompt_inplace() { powerlevel9k_refresh_prompt_inplace } _p9k_precmd() { __p9k_exit_code=$? __p9k_pipe_exit_codes=( $pipestatus ) + (( $#__p9k_pipe_exit_codes == 1 )) && __p9k_pipe_exit_codes[1]=$__p9k_exit_code __p9k_timer_end=EPOCHREALTIME if (( $+_p9k_real_zle_rprompt_indent )); then @@ -3568,8 +3548,14 @@ _p9k_init_params() { _p9k_declare -b POWERLEVEL9K_CHRUBY_SHOW_ENGINE 1 _p9k_declare -b POWERLEVEL9K_STATUS_CROSS 0 _p9k_declare -b POWERLEVEL9K_STATUS_OK 1 + _p9k_declare -b POWERLEVEL9K_STATUS_OK_PIPE 1 + _p9k_declare -b POWERLEVEL9K_STATUS_ERROR 1 + _p9k_declare -b POWERLEVEL9K_STATUS_ERROR_PIPE 1 + _p9k_declare -b POWERLEVEL9K_STATUS_ERROR_SIGNAL 1 _p9k_declare -b POWERLEVEL9K_STATUS_SHOW_PIPESTATUS 1 _p9k_declare -b POWERLEVEL9K_STATUS_HIDE_SIGNAME 0 + _p9k_declare -b POWERLEVEL9K_STATUS_VERBOSE_SIGNAME 1 + _p9k_declare -b POWERLEVEL9K_STATUS_EXTENDED_STATES 0 _p9k_declare -b POWERLEVEL9K_STATUS_VERBOSE 1 _p9k_declare -b POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE 0 # Format for the current time: 09:51:02. See `man 3 strftime`. @@ -4152,6 +4138,18 @@ _p9k_init() { typeset -grA __p9k_char2byte fi + if _p9k_segment_in_use status; then + typeset -g _p9k_exitcode2str=({0..255}) + local -i i=2 + if (( !_POWERLEVEL9K_STATUS_HIDE_SIGNAME )); then + for ((; i <= $#signals; ++i)); do + local sig=$signals[i] + (( _POWERLEVEL9K_STATUS_VERBOSE_SIGNAME )) && sig="SIG${sig}($((i-1)))" + _p9k_exitcode2str[$((128+i))]=$sig + done + fi + fi + _p9k_wrap_zle_widget zle-keymap-select _p9k_zle_keymap_select } From ec1632796f51aab056d62943d1ac6aeec0698c19 Mon Sep 17 00:00:00 2001 From: romkatv Date: Fri, 26 Jul 2019 15:37:21 +0200 Subject: [PATCH 02/11] remove unused parameter --- config/p10k-lean.zsh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index dfe03de4..9017a003 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -328,12 +328,6 @@ fi # like this: 1|0. prompt_char is green in this case. typeset -g POWERLEVEL9K_STATUS_OK_PIPE=true typeset -g POWERLEVEL9K_STATUS_OK_PIPE_FOREGROUND=9 - - # Don't show status unless the last command was terminated by a signal. Your prompt symbol - # (prompt_char) indicates error by turning red. Error codes aren't usually interesting but - # signals are. This shows signals as "INT", "ABORT", "KILL", etc. You can remove this parameter - # for more verbose output. - typeset -g POWERLEVEL9K_STATUS_ERROR_CONTENT_EXPANSION='${${P9K_CONTENT#SIG}//[!A-Z]}' ###################[ command_execution_time: duration of the last command ]################### # Show duration of the last command if takes longer than this many seconds. From 5e6acdc8fb40a38a9c97371e4cbbc021b3fe5dea Mon Sep 17 00:00:00 2001 From: romkatv Date: Fri, 26 Jul 2019 15:57:06 +0200 Subject: [PATCH 03/11] comments --- config/p10k-lean.zsh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index 9017a003..94b2abd2 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -93,11 +93,10 @@ fi # Powerline font to use them. See POWERLEVEL9K_MODE below. typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION= - # This option doesn't make a difference unless you've enabled default icons for all or some - # prompt segments (see POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION above). Default icons depend on - # the value of POWERLEVEL9K_MODE. For example, LOCK_ICON can be printed as $'\uE0A2', $'\uE138' - # or $'\uF023' depending on POWERLEVEL9K_MODE. The correct value of this parameter depends on - # the provider of the font your terminal is using. + # This option makes a difference only when default icons are enabled for all or some prompt + # segments (see POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION above). LOCK_ICON can be printed as + # $'\uE0A2', $'\uE138' or $'\uF023' depending on POWERLEVEL9K_MODE. The correct value of this + # parameter depends on the provider of the font your terminal is using. # # Font Provider | POWERLEVEL9K_MODE # ---------------------------------+------------------- @@ -108,6 +107,13 @@ fi # Awesome-Terminal Fonts (regular) | awesome-fontconfig # Awesome-Terminal Fonts (patched) | awesome-patched # Nerd Fonts | nerdfont-complete + # Other | compatible + # + # If this looks overwhelming, either stick with a preinstalled system font and set + # POWERLEVEL9K_MODE=compatible, or install a font from https://github.com/ryanoasis/nerd-fonts + # and set POWERLEVEL9K_MODE=nerdfont-complete. "Meslo LG S Regular Nerd Font Complete Mono" from + # https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/Meslo/S/Regular/complete is + # very good. typeset -g POWERLEVEL9K_MODE=nerdfont-complete # When set to true, icons appear before content on both sides of the prompt. When set From 69fbd901d6b54bf9276f7881711229fd1a796583 Mon Sep 17 00:00:00 2001 From: romkatv Date: Fri, 26 Jul 2019 16:22:21 +0200 Subject: [PATCH 04/11] comments --- config/p10k-classic.zsh | 2 +- config/p10k-lean.zsh | 65 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/config/p10k-classic.zsh b/config/p10k-classic.zsh index 42074978..758928cb 100644 --- a/config/p10k-classic.zsh +++ b/config/p10k-classic.zsh @@ -114,7 +114,7 @@ fi typeset -g POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW=false # Show node version only when in a directory tree containing package.json. - typeset -g P9K_NODE_VERSION_PROJECT_ONLY=true + typeset -g POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=true # Kubernetes context classes for the purpose of using different colors with # different contexts. diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index 94b2abd2..b7fe9060 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -1,5 +1,5 @@ -# Config for Powerlevel10k with lean prompt style. Doesn't require a Powerline font. -# The color scheme is suitable for dark terminal background. +# Config for Powerlevel10k with lean prompt style. Doesn't require a custom font but can take +# advantage of it if available. The color scheme is suitable for dark terminal background. # # Once you've installed Powerlevel10k, run these commands to apply lean style. # @@ -89,8 +89,12 @@ fi # such as POWERLEVEL9K_LOCK_ICON='⭐'. This will change the icon in every segment that uses # LOCK_ICON as default icon. If this paragraph looks confusing, forget what it says. # + # Note: You can use $'\u2B50' instead of '⭐'. It's especially convenient when specifying + # icons that your text editor cannot render. Don't forget to put $ and use single quotes when + # defining icons via Unicode codepoints. + # # Note: Many default icons cannot be displayed with system fonts. You'll need to install a - # Powerline font to use them. See POWERLEVEL9K_MODE below. + # capable font to use them. See POWERLEVEL9K_MODE below. typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION= # This option makes a difference only when default icons are enabled for all or some prompt @@ -240,7 +244,9 @@ fi # # ⌂ ~/best/powerlevel10k # - # You can also set different colors for directories of different classes. + # You can also set different colors for directories of different classes. Remember to override + # FOREGROUND, SHORTENED_FOREGROUND and ANCHOR_FOREGROUND for every directory class that you wish + # to have its own color. # # typeset -g POWERLEVEL9K_DIR_WORK_FOREGROUND=12 # typeset -g POWERLEVEL9K_DIR_WORK_SHORTENED_FOREGROUND=4 @@ -280,7 +286,7 @@ fi # If P9K_CONTENT is not empty, leave it unchanged. It's either "loading" or from vcs_info. vcs="\${P9K_CONTENT:-$vcs}" - # Branch icon. Set this parameter to '\uF126 ' for the popular Powerline branch icon. + # Branch icon. Set this parameter to $'\uF126 ' for the popular Powerline branch icon. typeset -g POWERLEVEL9K_VCS_BRANCH_ICON= # Disable the default Git status formatting. @@ -334,6 +340,12 @@ fi # like this: 1|0. prompt_char is green in this case. typeset -g POWERLEVEL9K_STATUS_OK_PIPE=true typeset -g POWERLEVEL9K_STATUS_OK_PIPE_FOREGROUND=9 + # Custom icons. + # typeset -g POWERLEVEL9K_STATUS_OK_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_STATUS_OK_PIPE_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_STATUS_ERROR_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_STATUS_ERROR_PIPE_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_STATUS_ERROR_SIGNAL_VISUAL_IDENTIFIER_EXPANSION='⭐' ###################[ command_execution_time: duration of the last command ]################### # Show duration of the last command if takes longer than this many seconds. @@ -344,6 +356,8 @@ fi typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND=101 # Duration format: 1d 2h 3m 4s. typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT='d h m s' + # Custom icon. + # typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_VISUAL_IDENTIFIER_EXPANSION='⭐' #######################[ background_jobs: presence of background jobs ]####################### # Don't show the number of background jobs. @@ -352,6 +366,8 @@ fi typeset -g POWERLEVEL9K_BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION='⇶' # Background jobs icon color. typeset -g POWERLEVEL9K_BACKGROUND_JOBS_VISUAL_IDENTIFIER_COLOR=2 + # Custom icon. + # typeset -g POWERLEVEL9K_BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION='⭐' ##########[ nordvpn: nordvpn connection status, linux only (https://nordvpn.com/) ]########### # NordVPN connection indicator color when connected. @@ -361,6 +377,11 @@ fi # Uncomment these two lines to hide NordVPN connection indicator when not connected. # typeset -g POWERLEVEL9K_NORDVPN_{DISCONNECTED,CONNECTING,DISCONNECTING}_CONTENT_EXPANSION= # typeset -g POWERLEVEL9K_NORDVPN_{DISCONNECTED,CONNECTING,DISCONNECTING}_VISUAL_IDENTIFIER_EXPANSION= + # Custom icons. + # typeset -g POWERLEVEL9K_NORDVPN_CONNECTED_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_NORDVPN_DISCONNECTED_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_NORDVPN_CONNECTING_VISUAL_IDENTIFIER_EXPANSION='⭐' + # typeset -g POWERLEVEL9K_NORDVPN_DISCONNECTING_VISUAL_IDENTIFIER_EXPANSION='⭐' ####################################[ context: user@host ]#################################### # Context format: user@host. @@ -372,6 +393,10 @@ fi # Don't show context unless running with privileges on in SSH. typeset -g POWERLEVEL9K_CONTEXT_{DEFAULT,SUDO}_{CONTENT,VISUAL_IDENTIFIER}_EXPANSION= typeset -g POWERLEVEL9K_ALWAYS_SHOW_CONTEXT=true + # Custom icon. + # typeset -g POWERLEVEL9K_CONTEXT_VISUAL_IDENTIFIER_EXPANSION='⭐' + # Custom icon when root. + # typeset -g POWERLEVEL9K_CONTEXT_ROOT_VISUAL_IDENTIFIER_EXPANSION='⭐' ###[ virtualenv: python virtual environment (https://docs.python.org/3/library/venv.html) ]### # Python virtual environment color. @@ -380,6 +405,8 @@ fi typeset -g POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION=true # Separate environment name from Python version only with a space. typeset -g POWERLEVEL9K_VIRTUALENV_{LEFT,RIGHT}_DELIMITER= + # Custom icon. + # typeset -g POWERLEVEL9K_VIRTUALENV_VISUAL_IDENTIFIER_EXPANSION='⭐' #####################[ anaconda: conda environment (https://conda.io/) ]###################### # Anaconda environment color. @@ -388,32 +415,44 @@ fi typeset -g POWERLEVEL9K_ANACONDA_SHOW_PYTHON_VERSION=true # Separate environment name from Python version only with a space. typeset -g POWERLEVEL9K_ANACONDA_{LEFT,RIGHT}_DELIMITER= + # Custom icon. + # typeset -g POWERLEVEL9K_ANACONDA_VISUAL_IDENTIFIER_EXPANSION='⭐' ################[ pyenv: python environment (https://github.com/pyenv/pyenv) ]################ # Pyenv color. typeset -g POWERLEVEL9K_PYENV_FOREGROUND=6 # Don't show the current Python version if it's the same as global. typeset -g POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW=false + # Custom icon. + # typeset -g POWERLEVEL9K_PYENV_VISUAL_IDENTIFIER_EXPANSION='⭐' ##########[ nodenv: node.js version from nodenv (https://github.com/nodenv/nodenv) ]########## # Nodenv color. typeset -g POWERLEVEL9K_NODENV_FOREGROUND=2 # Don't show node version if it's the same as global: $(nodenv version-name) == $(nodenv global). typeset -g POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW=false + # Custom icon. + # typeset -g POWERLEVEL9K_NODENV_VISUAL_IDENTIFIER_EXPANSION='⭐' ##############[ nvm: node.js version from nvm (https://github.com/nvm-sh/nvm) ]############### # Nvm color. typeset -g POWERLEVEL9K_NVM_FOREGROUND=2 + # Custom icon. + # typeset -g POWERLEVEL9K_NVM_VISUAL_IDENTIFIER_EXPANSION='⭐' ############[ nodeenv: node.js environment (https://github.com/ekalinin/nodeenv) ]############ # Nodeenv color. typeset -g POWERLEVEL9K_NODEENV_FOREGROUND=2 + # Custom icon. + # typeset -g POWERLEVEL9K_NODEENV_VISUAL_IDENTIFIER_EXPANSION='⭐' ##############################[ node_version: node.js version ]############################### # Node version color. typeset -g POWERLEVEL9K_NODE_VERSION_FOREGROUND=2 # Show node version only when in a directory tree containing package.json. - typeset -g P9K_NODE_VERSION_PROJECT_ONLY=true + typeset -g POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=true + # Custom icon. + # typeset -g POWERLEVEL9K_NODE_VERSION_VISUAL_IDENTIFIER_EXPANSION='⭐' #############[ kubecontext: current kubernetes context (https://kubernetes.io/) ]############# # Kubernetes context classes for the purpose of using different colors with @@ -434,8 +473,12 @@ fi # '*test*' TEST # to match your needs. Customize them as needed. '*' DEFAULT) # typeset -g POWERLEVEL9K_KUBECONTEXT_PROD_FOREGROUND=1 + # typeset -g POWERLEVEL9K_KUBECONTEXT_PROD_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_FOREGROUND=2 + # typeset -g POWERLEVEL9K_KUBECONTEXT_TEST_VISUAL_IDENTIFIER_EXPANSION='⭐' typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_FOREGROUND=3 + # typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_VISUAL_IDENTIFIER_EXPANSION='⭐' + # Kubernetes context too long? You can shorten it by defining an expansion. The original # Kubernetes context that you see in your prompt is stored in ${P9K_CONTENT} when # the expansion is evaluated. To remove everything up to and including the last '/', @@ -444,12 +487,15 @@ fi # are very flexible and fast, too. See reference: # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion. typeset POWERLEVEL9K_KUBECONTEXT_CONTENT_EXPANSION='${P9K_CONTENT}' - # Show the trailing "/default" in kubernetes context. + # Show the trailing "/default" in kubernetes context. This makes it easier to define + # POWERLEVEL9K_KUBECONTEXT_CONTENT_EXPANSION by making the format of ${P9K_CONTENT} consistent. typeset -g POWERLEVEL9K_KUBECONTEXT_SHOW_DEFAULT_NAMESPACE=true ###############################[ public_ip: public IP address ]############################### # Public IP color. typeset -g POWERLEVEL9K_PUBLIC_IP_FOREGROUND=144 + # Custom icon. + # typeset -g POWERLEVEL9K_PUBLIC_IP_VISUAL_IDENTIFIER_EXPANSION='⭐' ################################[ battery: internal battery ]################################# # Show battery in red when it's below this level and not connected to power supply. @@ -467,6 +513,9 @@ fi typeset -g POWERLEVEL9K_BATTERY_CHARGED_{CONTENT,VISUAL_IDENTIFIER}_EXPANSION= # Don't show the remaining time to charge/discharge. typeset -g POWERLEVEL9K_BATTERY_VERBOSE=false + # Disable the default icon because POWERLEVEL9K_BATTERY_STAGES is enough to cue the meaning + # of this segment. + typeset -g POWERLEVEL9K_BATTERY_VISUAL_IDENTIFIER_EXPANSION= ####################################[ time: current time ]#################################### # Current time color. @@ -477,6 +526,8 @@ fi # commands will contain the start times of their commands as opposed to the default # behavior where they contain the end times of their preceding commands. typeset -g POWERLEVEL9K_TIME_UPDATE_ON_COMMAND=false + # Custom icon. + # typeset -g POWERLEVEL9K_TIME_VISUAL_IDENTIFIER_EXPANSION='⭐' } (( ! p10k_lean_restore_aliases )) || setopt aliases From 93857552cfe8a407e155cd6180173492dccbcd01 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sat, 27 Jul 2019 00:19:04 +0200 Subject: [PATCH 05/11] recognize vivis and vivli keymaps as visual vi mode These keymaps are created by https://github.com/b4b4r07/zsh-vimode-visual. I don't know why anyone would use this instead of the standard `v` and `V` keybindings. Requested in https://github.com/romkatv/powerlevel10k/issues/134. --- internal/p10k.zsh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 73c7fc68..7a28feee 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -2101,13 +2101,13 @@ prompt_status() { prompt_prompt_char() { if (( __p9k_exit_code )); then - _p9k_prompt_segment $0_ERROR_VIINS "$_p9k_color1" 196 '' 0 '${${KEYMAP:-0}:#vicmd}' '❯' + _p9k_prompt_segment $0_ERROR_VIINS "$_p9k_color1" 196 '' 0 '${${KEYMAP:-0}:#(vicmd|vivis|vivli)}' '❯' _p9k_prompt_segment $0_ERROR_VICMD "$_p9k_color1" 196 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd0}' '❮' - _p9k_prompt_segment $0_ERROR_VIVIS "$_p9k_color1" 196 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd1}' 'Ⅴ' + _p9k_prompt_segment $0_ERROR_VIVIS "$_p9k_color1" 196 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#(vicmd1|vivis?|vivli?)}' 'Ⅴ' else - _p9k_prompt_segment $0_OK_VIINS "$_p9k_color1" 76 '' 0 '${${KEYMAP:-0}:#vicmd}' '❯' + _p9k_prompt_segment $0_OK_VIINS "$_p9k_color1" 76 '' 0 '${${KEYMAP:-0}:#(vicmd|vivis|vivli)}' '❯' _p9k_prompt_segment $0_OK_VICMD "$_p9k_color1" 76 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd0}' '❮' - _p9k_prompt_segment $0_OK_VIVIS "$_p9k_color1" 76 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd1}' 'Ⅴ' + _p9k_prompt_segment $0_OK_VIVIS "$_p9k_color1" 76 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#(vicmd1|vivis?|vivli?)}' 'Ⅴ' fi } @@ -2765,13 +2765,13 @@ prompt_vcs() { # Vi Mode: show editing mode (NORMAL|INSERT|VISUAL) prompt_vi_mode() { if [[ -n $_POWERLEVEL9K_VI_INSERT_MODE_STRING ]]; then - _p9k_prompt_segment $0_INSERT "$_p9k_color1" blue '' 0 '${${KEYMAP:-0}:#vicmd}' "$_POWERLEVEL9K_VI_INSERT_MODE_STRING" + _p9k_prompt_segment $0_INSERT "$_p9k_color1" blue '' 0 '${${KEYMAP:-0}:#(vicmd|vivis|vivli)}' "$_POWERLEVEL9K_VI_INSERT_MODE_STRING" fi if (( $+_POWERLEVEL9K_VI_VISUAL_MODE_STRING )); then _p9k_prompt_segment $0_NORMAL "$_p9k_color1" white '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd0}' "$_POWERLEVEL9K_VI_COMMAND_MODE_STRING" - _p9k_prompt_segment $0_VISUAL "$_p9k_color1" white '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd1}' "$_POWERLEVEL9K_VI_VISUAL_MODE_STRING" + _p9k_prompt_segment $0_VISUAL "$_p9k_color1" white '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#(vicmd1|vivis?|vivli?)}' "$_POWERLEVEL9K_VI_VISUAL_MODE_STRING" else - _p9k_prompt_segment $0_NORMAL "$_p9k_color1" white '' 0 '${(M)KEYMAP:#vicmd}' "$_POWERLEVEL9K_VI_COMMAND_MODE_STRING" + _p9k_prompt_segment $0_NORMAL "$_p9k_color1" white '' 0 '${(M)KEYMAP:#(vicmd|vivis|vivli)}' "$_POWERLEVEL9K_VI_COMMAND_MODE_STRING" fi } From 57044e5a5cad457c79e33df446218e50c91ab340 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sat, 27 Jul 2019 00:42:35 +0200 Subject: [PATCH 06/11] typo: -O => -o --- config/p10k-lean.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index b7fe9060..30bfce7d 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -3,7 +3,7 @@ # # Once you've installed Powerlevel10k, run these commands to apply lean style. # -# curl -fsSL -O ~/p10k-lean.zsh https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-lean.zsh +# curl -fsSL -o ~/p10k-lean.zsh https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-lean.zsh # echo 'source ~/p10k-lean.zsh' >>! ~/.zshrc # # To customize your prompt, open ~/p10k-lean.zsh in your favorite text editor, change it and From 436740db8ece184ace58cc6791d57cb3540d529d Mon Sep 17 00:00:00 2001 From: romkatv Date: Sat, 27 Jul 2019 12:09:09 +0200 Subject: [PATCH 07/11] fix many bugs in status related to pipelines --- internal/p10k.zsh | 119 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 88 insertions(+), 31 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 7a28feee..b8552dbf 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -1231,8 +1231,8 @@ _p9k_custom_prompt() { ################################################################ # Display the duration the command needed to run. prompt_command_execution_time() { - (( __p9k_timer_start )) || return - P9K_COMMAND_DURATION_SECONDS=$((__p9k_timer_end - __p9k_timer_start)) + (( _p9k_timer_start )) || return + P9K_COMMAND_DURATION_SECONDS=$((_p9k_timer_end - _p9k_timer_start)) (( P9K_COMMAND_DURATION_SECONDS >= _POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )) || return if (( P9K_COMMAND_DURATION_SECONDS < 60 )); then @@ -2065,23 +2065,27 @@ prompt_ssh() { # Status: When an error occur, return the error code, or a cross icon if option is set # Display an ok icon when no error occur, or hide the segment if option is set to false prompt_status() { - if ! _p9k_cache_get $0 $__p9k_exit_code $__p9k_pipe_exit_codes; then - (( __p9k_exit_code )) && local state=ERROR || local state=OK + if ! _p9k_cache_get $0 $_p9k_status $_p9k_pipestatus; then + (( _p9k_status )) && local state=ERROR || local state=OK if (( _POWERLEVEL9K_STATUS_EXTENDED_STATES )); then - if (( __p9k_exit_code )); then - if (( $#__p9k_pipe_exit_codes > 1 )); then + if (( _p9k_status )); then + if (( $#_p9k_pipestatus > 1 )); then state+=_PIPE - elif (( __p9k_exit_code > 128 )); then + elif (( _p9k_status > 128 )); then state+=_SIGNAL fi - elif [[ "$__p9k_pipe_exit_codes" == *[1-9]* ]]; then + elif [[ "$_p9k_pipestatus" == *[1-9]* ]]; then state+=_PIPE fi fi _p9k_cache_val=(:) if (( _POWERLEVEL9K_STATUS_$state )); then - local text=${(j:|:)${(@)__p9k_pipe_exit_codes:/(#b)(*)/$_p9k_exitcode2str[$match[1]+1]}} - if (( __p9k_exit_code )); then + if (( _POWERLEVEL9K_STATUS_SHOW_PIPESTATUS )); then + local text=${(j:|:)${(@)_p9k_pipestatus:/(#b)(*)/$_p9k_exitcode2str[$match[1]+1]}} + else + local text=$_p9k_exitcode2str[_p9k_status+1] + fi + if (( _p9k_status )); then if (( !_POWERLEVEL9K_STATUS_CROSS && _POWERLEVEL9K_STATUS_VERBOSE )); then _p9k_cache_val=($0_$state red yellow1 CARRIAGE_RETURN_ICON 0 '' "$text") else @@ -2092,7 +2096,7 @@ prompt_status() { _p9k_cache_val=($0_$state "$_p9k_color1" green OK_ICON 0 '' "$text") fi fi - if (( $#__p9k_pipe_exit_codes < 3 )); then + if (( $#_p9k_pipestatus < 3 )); then _p9k_cache_set "${(@)_p9k_cache_val}" fi fi @@ -2100,7 +2104,7 @@ prompt_status() { } prompt_prompt_char() { - if (( __p9k_exit_code )); then + if (( _p9k_status )); then _p9k_prompt_segment $0_ERROR_VIINS "$_p9k_color1" 196 '' 0 '${${KEYMAP:-0}:#(vicmd|vivis|vivli)}' '❯' _p9k_prompt_segment $0_ERROR_VICMD "$_p9k_color1" 196 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#vicmd0}' '❮' _p9k_prompt_segment $0_ERROR_VIVIS "$_p9k_color1" 196 '' 0 '${(M)${:-$KEYMAP$_p9k_region_active}:#(vicmd1|vivis?|vivli?)}' 'Ⅴ' @@ -2187,7 +2191,7 @@ prompt_time() { t=$_p9k_ret _p9k_escape $_POWERLEVEL9K_TIME_FORMAT _p9k_prompt_segment "$0" "$_p9k_color2" "$_p9k_color1" "TIME_ICON" 1 '' \ - "\${_p9k_line_finish-$t}\${_p9k_line_finish+$_p9k_ret}" + "\${_p9k_line_finished-$t}\${_p9k_line_finished+$_p9k_ret}" else _p9k_prompt_segment "$0" "$_p9k_color2" "$_p9k_color1" "TIME_ICON" 0 '' $t fi @@ -3034,7 +3038,8 @@ _p9k_preexec() { fi unset _p9k_real_zle_rprompt_indent fi - __p9k_timer_start=EPOCHREALTIME + _p9k_preexec_cmd=$2 + _p9k_timer_start=EPOCHREALTIME } function _p9k_build_segment() { @@ -3048,8 +3053,6 @@ function _p9k_build_segment() { } function _p9k_set_prompt() { - unset _p9k_line_finish - unset _p9k_rprompt_override PROMPT=$_p9k_prompt_prefix_left RPROMPT= @@ -3079,7 +3082,9 @@ function _p9k_set_prompt() { left_idx=_p9k_segment_index _p9k_prompt+=$_p9k_line_suffix_left[i] if (( $+_p9k_dir || (i != num_lines && $#right) )); then - PROMPT+='${${:-${_p9k_d::=0}${_p9k_rprompt::=${_p9k_rprompt_override-'$right'}}${_p9k_lprompt::='$_p9k_prompt'}}+}' + PROMPT+='${${:-${_p9k_d::=0}${_p9k_rprompt::=' + [[ -o transient_rprompt ]] && PROMPT+='${_p9k_line_finished-'$right'}' || PROMPT+=$right + PROMPT+='}${_p9k_lprompt::='$_p9k_prompt'}}+}' PROMPT+=$_p9k_gap_pre if (( $+_p9k_dir )); then if (( i == num_lines && (_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS > 0 || _POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT > 0) )); then @@ -3144,11 +3149,55 @@ powerlevel9k_refresh_prompt_inplace() { p9k_refresh_prompt_inplace() { powerlevel9k_refresh_prompt_inplace } +typeset -ga __p9k_last_cmd_state + +_p9k_save_status() { + emulate -L zsh && setopt no_hist_expand extended_glob + local -i pipe + if (( !$+_p9k_line_finished )); then + : # SIGINT + elif (( !$+_p9k_preexec_cmd )); then + # Empty line, comment or parse error. + # + # This case is handled incorrectly: + # + # true | false + # | + # + # Here status=1 and pipestatus=(0 1). Ideally we should ignore pipestatus but we won't. + # + # This works though (unless pipefail is set): + # + # false | true + # | + # + # We get status=1 and pipestatus=(1 0) and correctly ignore pipestatus. + (( _p9k_status == __p9k_last_cmd_state[2] )) && return + elif (( ${${__p9k_last_cmd_state[3,-1]}[(I)$__p9k_last_cmd_state[2]]} )); then # just in case + local cmd=(${(z)_p9k_preexec_cmd}) + if [[ $#cmd != 0 && $cmd[1] != '!' && ${(Q)cmd[1]} != coproc ]]; then + local arg + for arg in ${(z)_p9k_preexec_cmd}; do + # '()' is for functions, *';' is for complex commands. + if [[ $arg == ('()'|'&&'|'||'|'&'|'&|'|'&!'|*';') ]]; then + pipe=0 + break + elif [[ $arg == *('|'|'|&')* ]]; then + pipe=1 + fi + done + fi + fi + _p9k_status=$__p9k_last_cmd_state[2] + if (( pipe )); then + _p9k_pipestatus=($__p9k_last_cmd_state[3,-1]) + else + _p9k_pipestatus=($__p9k_last_cmd_state[2]) + fi +} + _p9k_precmd() { - __p9k_exit_code=$? - __p9k_pipe_exit_codes=( $pipestatus ) - (( $#__p9k_pipe_exit_codes == 1 )) && __p9k_pipe_exit_codes[1]=$__p9k_exit_code - __p9k_timer_end=EPOCHREALTIME + __p9k_last_cmd_state=($EPOCHREALTIME $? $pipestatus) if (( $+_p9k_real_zle_rprompt_indent )); then if [[ -n $_p9k_real_zle_rprompt_indent ]]; then @@ -3165,9 +3214,14 @@ _p9k_precmd() { prompt_opts=(cr percent sp subst) setopt nopromptbang prompt{cr,percent,sp,subst} + _p9k_timer_end=$__p9k_last_cmd_state[1] + _p9k_save_status + powerlevel9k_refresh_prompt_inplace - __p9k_timer_start=0 + unset _p9k_line_finished + unset _p9k_preexec_cmd + _p9k_timer_start=0 _p9k_region_active=0 } @@ -3343,6 +3397,11 @@ function _p9k_prompt_overflow_bug() { } _p9k_init_vars() { + typeset -gi _p9k_reset_on_line_finish + typeset -gF _p9k_timer_start + typeset -gF _p9k_timer_end + typeset -gi _p9k_status + typeset -ga _p9k_pipestatus typeset -g _p9k_param_sig typeset -g _p9k_ret typeset -g _p9k_cache_key @@ -3657,9 +3716,8 @@ _p9k_wrap_zle_widget() { function _p9k_zle_line_finish() { (( __p9k_enabled )) || return - [[ ! -o TRANSIENT_RPROMPT ]] || _p9k_rprompt_override= - _p9k_line_finish= - zle && zle .reset-prompt && zle -R + _p9k_line_finished= + (( _p9k_reset_on_line_finish )) && zle && zle .reset-prompt && zle -R } function _p9k_zle_line_pre_redraw() { @@ -3888,8 +3946,11 @@ _p9k_init_prompt() { _p9k_prompt_prefix_left+="%{$(iterm2_prompt_mark)%}" fi - if [[ -o TRANSIENT_RPROMPT && -n "$_p9k_line_segments_right[2,-1]" ]] || - ( _p9k_segment_in_use time && (( _POWERLEVEL9K_TIME_UPDATE_ON_COMMAND )) ); then + [[ -o transient_rprompt && -n "$_p9k_line_segments_right[1,-2]" ]] || + ( _p9k_segment_in_use time && (( _POWERLEVEL9K_TIME_UPDATE_ON_COMMAND )) ) + _p9k_reset_on_line_finish=$((!$?)) + + if _p9k_reset_on_line_finish || _p9k_segment_in_use status; then _p9k_wrap_zle_widget zle-line-finish _p9k_zle_line_finish fi } @@ -4165,10 +4226,6 @@ prompt_powerlevel9k_setup() { emulate -L zsh && setopt no_hist_expand extended_glob prompt_powerlevel9k_teardown __p9k_enabled=1 - typeset -gF __p9k_timer_start=0 - typeset -gF __p9k_timer_end=0 - typeset -gi __p9k_exit_code=0 - typeset -ga __p9k_pipe_exit_codes=() add-zsh-hook preexec _p9k_preexec add-zsh-hook precmd _p9k_precmd } From b66d6a71056b543aadc4249806e818002fd42813 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sat, 27 Jul 2019 12:14:16 +0200 Subject: [PATCH 08/11] typo --- internal/p10k.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index b8552dbf..b4d0cb80 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3950,7 +3950,7 @@ _p9k_init_prompt() { ( _p9k_segment_in_use time && (( _POWERLEVEL9K_TIME_UPDATE_ON_COMMAND )) ) _p9k_reset_on_line_finish=$((!$?)) - if _p9k_reset_on_line_finish || _p9k_segment_in_use status; then + if (( _p9k_reset_on_line_finish )) || _p9k_segment_in_use status; then _p9k_wrap_zle_widget zle-line-finish _p9k_zle_line_finish fi } From 80770d6a792bf4967a4c4695dde84d07c46dc6a9 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sat, 27 Jul 2019 12:27:56 +0200 Subject: [PATCH 09/11] fix status on zsh 5.1 --- internal/p10k.zsh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index b4d0cb80..25acf8f2 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3149,7 +3149,8 @@ powerlevel9k_refresh_prompt_inplace() { p9k_refresh_prompt_inplace() { powerlevel9k_refresh_prompt_inplace } -typeset -ga __p9k_last_cmd_state +typeset -gi __p9k_new_status +typeset -ga __p9k_new_pipestatus _p9k_save_status() { emulate -L zsh && setopt no_hist_expand extended_glob @@ -3172,8 +3173,8 @@ _p9k_save_status() { # | # # We get status=1 and pipestatus=(1 0) and correctly ignore pipestatus. - (( _p9k_status == __p9k_last_cmd_state[2] )) && return - elif (( ${${__p9k_last_cmd_state[3,-1]}[(I)$__p9k_last_cmd_state[2]]} )); then # just in case + (( _p9k_status == __p9k_new_status )) && return + elif (( $__p9k_new_pipestatus[(I)$__p9k_new_status] )); then # just in case local cmd=(${(z)_p9k_preexec_cmd}) if [[ $#cmd != 0 && $cmd[1] != '!' && ${(Q)cmd[1]} != coproc ]]; then local arg @@ -3188,16 +3189,17 @@ _p9k_save_status() { done fi fi - _p9k_status=$__p9k_last_cmd_state[2] + _p9k_status=$__p9k_new_status if (( pipe )); then - _p9k_pipestatus=($__p9k_last_cmd_state[3,-1]) + _p9k_pipestatus=($__p9k_new_pipestatus) else - _p9k_pipestatus=($__p9k_last_cmd_state[2]) + _p9k_pipestatus=($_p9k_status) fi } _p9k_precmd() { - __p9k_last_cmd_state=($EPOCHREALTIME $? $pipestatus) + __p9k_new_status=$? + __p9k_new_pipestatus=($pipestatus) if (( $+_p9k_real_zle_rprompt_indent )); then if [[ -n $_p9k_real_zle_rprompt_indent ]]; then @@ -3214,7 +3216,7 @@ _p9k_precmd() { prompt_opts=(cr percent sp subst) setopt nopromptbang prompt{cr,percent,sp,subst} - _p9k_timer_end=$__p9k_last_cmd_state[1] + _p9k_timer_end=EPOCHREALTIME _p9k_save_status powerlevel9k_refresh_prompt_inplace From b27ff42ac373143b9196228f3445327121ee4be4 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sat, 27 Jul 2019 13:18:09 +0200 Subject: [PATCH 10/11] do nothing in p9k_prompt_segment if not called by p10k --- internal/p10k.zsh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 25acf8f2..bf7365cc 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -911,8 +911,7 @@ Example customizations: POWERLEVEL9K_CORE_PROTECTED_VISUAL_IDENTIFIER_EXPANSION='❎' # Don't show file size when PROTECTED. - POWERLEVEL9K_CORE_PROTECTED_CONTENT_EXPANSION='' -" + POWERLEVEL9K_CORE_PROTECTED_CONTENT_EXPANSION=''" # Type `p9k_prompt_segment -h` for usage. function p9k_prompt_segment() { @@ -938,9 +937,11 @@ function p9k_prompt_segment() { echo -E - $__p9k_prompt_segment_usage >&2 return 1 } - (( ref )) || icon=$'\1'$icon - "_p9k_${_p9k_prompt_side}_prompt_segment" "prompt_${_p9k_segment_name}${state:+_${(U)state}}" \ - "$bg" "${fg:-$_p9k_color1}" "$icon" "$expand" "$cond" "$text" + if [[ -n $_p9k_prompt_side ]]; then + (( ref )) || icon=$'\1'$icon + "_p9k_${_p9k_prompt_side}_prompt_segment" "prompt_${_p9k_segment_name}${state:+_${(U)state}}" \ + "$bg" "${fg:-$_p9k_color1}" "$icon" "$expand" "$cond" "$text" + fi return 0 } @@ -3129,6 +3130,7 @@ function _p9k_set_prompt() { PROMPT+=$_p9k_prompt_suffix_left [[ -n $RPROMPT ]] && RPROMPT=$_p9k_prompt_prefix_right$RPROMPT$_p9k_prompt_suffix_right + _p9k_prompt_side= (( $#_p9k_cache < _POWERLEVEL9K_MAX_CACHE_SIZE )) || _p9k_cache=() } From 57b1f1aa744d3a990c1173ae5fe88d1e09e8c853 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sat, 27 Jul 2019 13:20:27 +0200 Subject: [PATCH 11/11] default background to black in p9k_prompt_segment; comments --- internal/p10k.zsh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index bf7365cc..ec56de18 100755 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -850,22 +850,22 @@ typeset -gr __p9k_prompt_segment_usage="Usage: p9k_prompt_segment [{+|-}re] [-s Options: -t text segment's main content; will undergo prompt expansion: '%F{blue}%T%f' will - show as blue current time - -i icon segment's icon + show as blue current time; default is empty + -i icon segment's icon; default is empty -r icon is a symbolic reference that needs to be resolved; for example, 'LOCK_ICON' +r icon is already resolved and should be printed literally; for example, '⭐'; this is the default; you can also use $'\u2B50' if you don't want to have non-ascii characters in source code -b bg background color; for example, 'blue', '4', or '#0000ff'; empty value means - transparent background, as in '%k' + transparent background, as in '%k'; default is black -f fg foreground color; for example, 'blue', '4', or '#0000ff'; empty value means - default foreground color, as in '%f' + default foreground color, as in '%f'; default is empty -s state segment's state for the purpose of applying styling options; if you want to to be able to use POWERLEVEL9K parameters to specify different colors or icons depending on some property, use different states for different values of that property -c condition; if empty after parameter expansion and process substitution, the - segment is hidden; this is an advanced feature, use with caution + segment is hidden; this is an advanced feature, use with caution; default is '1' -e segment's main content will undergo parameter expansion and process substitution; the content will be surrounded with double quotes and thus should quote its own double quotes; this is an advanced feature, use with @@ -916,7 +916,7 @@ Example customizations: # Type `p9k_prompt_segment -h` for usage. function p9k_prompt_segment() { emulate -L zsh && setopt no_hist_expand extended_glob - local opt state bg fg icon cond text ref=0 expand=0 + local opt state bg=0 fg icon cond text ref=0 expand=0 while getopts ':s:b:f:i:c:t:re' opt; do case $opt in s) state=$OPTARG;;