aboutsummaryrefslogtreecommitdiff
path: root/internal/p10k.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'internal/p10k.zsh')
-rw-r--r--internal/p10k.zsh86
1 files changed, 60 insertions, 26 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh
index 2adbc40f..f9e38f84 100644
--- a/internal/p10k.zsh
+++ b/internal/p10k.zsh
@@ -20,7 +20,7 @@ if [[ $__p9k_sourced != 13 ]]; then
return 1
fi
-if ! autoload -Uz is-at-least || ! is-at-least 5.1; then
+if [[ $ZSH_VERSION != (5.<1->*|<6->.*) ]]; then
() {
>&2 echo -E "You are using ZSH version $ZSH_VERSION. The minimum required version for Powerlevel10k is 5.1."
>&2 echo -E "Type 'echo \$ZSH_VERSION' to see your current zsh version."
@@ -31,8 +31,8 @@ if ! autoload -Uz is-at-least || ! is-at-least 5.1; then
>&2 echo -E "The shell you are currently running is likely $cur."
fi
local other=${${:-zsh}:c}
- if [[ -n $other ]] && $other -c 'autoload -Uz is-at-least && is-at-least 5.1' &>/dev/null; then
- local other_v="$($other -c 'echo -E $ZSH_VERSION' 2>/dev/null)"
+ if [[ -n $other ]] && $other -fc '[[ $ZSH_VERSION == (5.<1->*|<6->.*) ]]' &>/dev/null; then
+ local other_v="$($other -fc 'echo -E $ZSH_VERSION' 2>/dev/null)"
if [[ -n $other_v && $other_v != $ZSH_VERSION ]]; then
>&2 echo -E "You have $other with version $other_v but this is not what you are using."
if [[ -n $def && $def != ${other:A} ]]; then
@@ -341,7 +341,7 @@ function _p9k_human_readable_bytes() {
_p9k__ret=${${_p9k__ret%%0#}%.}$suf
}
-if is-at-least 5.4; then
+if [[ $ZSH_VERSION == (5.<4->*|<6->.*) ]]; then
function _p9k_print_params() { typeset -p -- "$@" }
else
# Cannot use `typeset -p` unconditionally because of bugs in zsh.
@@ -1349,7 +1349,7 @@ _p9k_prompt_battery_init() {
return
fi
if [[ $_p9k_os != (Linux|Android) ||
- -z /sys/class/power_supply/(CMB*|BAT*|battery)/(energy_full|charge_full|charge_counter)(#qN) ]]; then
+ -z /sys/class/power_supply/(CMB*|BAT*|*battery)/(energy_full|charge_full|charge_counter)(#qN) ]]; then
typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
fi
}
@@ -1407,7 +1407,7 @@ _p9k_prompt_battery_set_args() {
Linux|Android)
# See https://sourceforge.net/projects/acpiclient.
- local -a bats=( /sys/class/power_supply/(CMB*|BAT*|battery)/(FN) )
+ local -a bats=( /sys/class/power_supply/(CMB*|BAT*|*battery)/(FN) )
(( $#bats )) || return
local -i energy_now energy_full power_now
@@ -3116,6 +3116,25 @@ _p9k_prompt_plenv_init() {
}
################################################################
+# Segment to display perlbrew information
+# https://github.com/gugod/App-perlbrew
+
+prompt_perlbrew() {
+ if (( _POWERLEVEL9K_PERLBREW_PROJECT_ONLY )); then
+ _p9k_upglob 'cpanfile|.perltidyrc|(|MY)META.(yml|json)|(Makefile|Build).PL|*.(pl|pm|t|pod)' && return
+ fi
+
+ local v=$PERLBREW_PERL
+ (( _POWERLEVEL9K_PERLBREW_SHOW_PREFIX )) || v=${v#*-}
+ [[ -n $v ]] || return
+ _p9k_prompt_segment "$0" "blue" "$_p9k_color1" 'PERL_ICON' 0 '' "${v//\%/%%}"
+}
+
+_p9k_prompt_perlbrew_init() {
+ typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$PERLBREW_PERL'
+}
+
+################################################################
# Segment to display chruby information
# see https://github.com/postmodern/chruby/issues/245 for chruby_auto issue with ZSH
prompt_chruby() {
@@ -4464,7 +4483,7 @@ prompt_kubecontext() {
{
(( pos <= $#cfg )) || return
shift $pos cfg
- pos=${cfg[(i) name: $name]}
+ pos=${cfg[(i) name: ${(b)name}]}
(( pos <= $#cfg )) || return
(( --pos ))
for ((; pos > 0; --pos)); do
@@ -4628,9 +4647,9 @@ _p9k_gcloud_prefetch() {
# P9K_GCLOUD_PROJECT is deprecated; it's always equal to P9K_GCLOUD_PROJECT_ID
unset P9K_GCLOUD_CONFIGURATION P9K_GCLOUD_ACCOUNT P9K_GCLOUD_PROJECT P9K_GCLOUD_PROJECT_ID P9K_GCLOUD_PROJECT_NAME
(( $+commands[gcloud] )) || return
- _p9k_read_word ~/.config/gcloud/active_config || return
+ _p9k_read_word ${CLOUDSDK_CONFIG:-~/.config/gcloud}/active_config || return
P9K_GCLOUD_CONFIGURATION=$_p9k__ret
- if ! _p9k_cache_stat_get $0 ~/.config/gcloud/configurations/config_$P9K_GCLOUD_CONFIGURATION; then
+ if ! _p9k_cache_stat_get $0 ${CLOUDSDK_CONFIG:-~/.config/gcloud}/configurations/config_$P9K_GCLOUD_CONFIGURATION; then
local pair account project_id
pair="$(gcloud config configurations describe $P9K_GCLOUD_CONFIGURATION \
--format=$'value[separator="\1"](properties.core.account,properties.core.project)')"
@@ -4988,18 +5007,18 @@ _p9k_prompt_proxy_init() {
function prompt_direnv() {
local -i len=$#_p9k__prompt _p9k__has_upglob
- _p9k_prompt_segment $0 $_p9k_color1 yellow DIRENV_ICON 0 '$DIRENV_DIR' ''
+ _p9k_prompt_segment $0 $_p9k_color1 yellow DIRENV_ICON 0 '${DIRENV_DIR-}' ''
(( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
}
_p9k_prompt_direnv_init() {
# DIRENV_DIR is set in a precmd hook. If our hook isn't the last, DIRENV_DIR might
# still get set before prompt is expanded.
- typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${DIRENV_DIR:-${precmd_functions[-1]:#_p9k_precmd}}'
+ typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${DIRENV_DIR-${precmd_functions[-1]:#_p9k_precmd}}'
}
function instant_prompt_direnv() {
- if [[ -n $DIRENV_DIR && $precmd_functions[-1] == _p9k_precmd ]]; then
+ if [[ -n ${DIRENV_DIR:-} && $precmd_functions[-1] == _p9k_precmd ]]; then
_p9k_prompt_segment prompt_direnv $_p9k_color1 yellow DIRENV_ICON 0 '' ''
fi
}
@@ -5997,7 +6016,7 @@ _p9k_set_instant_prompt() {
[[ -n $RPROMPT ]] || unset RPROMPT
}
-typeset -gri __p9k_instant_prompt_version=45
+typeset -gri __p9k_instant_prompt_version=47
_p9k_dump_instant_prompt() {
local user=${(%):-%n}
@@ -6031,7 +6050,7 @@ _p9k_dump_instant_prompt() {
typeset -gi __p9k_instant_prompt_disabled=1
[[ \$ZSH_VERSION == ${(q)ZSH_VERSION} && \$ZSH_PATCHLEVEL == ${(q)ZSH_PATCHLEVEL} &&
$screen \${(M)TERM:#(screen*|tmux*)} &&
- \${#\${(M)VTE_VERSION:#(<1-4602>|4801)}} == ${#${(M)VTE_VERSION:#(<1-4602>|4801)}} &&
+ \${#\${(M)VTE_VERSION:#(<1-4602>|4801)}} == "${#${(M)VTE_VERSION:#(<1-4602>|4801)}}" &&
\$POWERLEVEL9K_DISABLE_INSTANT_PROMPT != 'true' &&
\$POWERLEVEL9K_INSTANT_PROMPT != 'off' ]] || return
typeset -g __p9k_instant_prompt_param_sig=${(q+)_p9k__param_sig}
@@ -6533,7 +6552,9 @@ function _p9k_clear_instant_prompt() {
unset _z4h_saved_screen
fi
print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed]
- local unexpected=${${${(S)content//$'\e[?'<->'c'}//$'\e['<->' q'}//$'\e'[^$'\a\e']#($'\a'|$'\e\\')}
+ local unexpected=${(S)${${content//$'\e[?'<->'c'}//$'\e['<->' q'}//$'\e'[^$'\a\e']#($'\a'|$'\e\\')}
+ # Visual Studio Code prints this garbage.
+ unexpected=${unexpected//$'\033[1;32mShell integration activated\033[0m\n'}
if [[ -n $unexpected ]]; then
local omz1='[Oh My Zsh] Would you like to update? [Y/n]: '
local omz2='Updating Oh My Zsh'
@@ -6995,7 +7016,7 @@ function _p9k_reset_prompt() {
zle .reset-prompt
(( ${+functions[z4h]} )) || zle -R
} always {
- (( _p9k__can_hide_cursor )) && echoti cnorm
+ (( _p9k__can_hide_cursor )) && print -rn -- $_p9k__cnorm
_p9k__cursor_hidden=0
}
fi
@@ -7007,14 +7028,14 @@ function _p9k_reset_prompt() {
# ZSH_PATCHLEVEL=zsh-5.4.2-159-gd8d9fee13. Released in 5.5.
#
# Fix: https://github.com/zsh-users/zsh/commit/64d13738357c9b9c212adbe17f271716abbcf6ea.
-# ZSH_PATCHLEVEL=zsh-5.7.1-50-g64d137383.
+# ZSH_PATCHLEVEL=zsh-5.7.1-50-g64d137383. Released in 5.7.2.
#
# Test: PROMPT="${(pl:$((COLUMNS))::-:)}<%1(l.%2(l.FAIL.PASS).FAIL)> " zsh -dfis <<<exit
# Workaround: PROMPT="${(pl:$((COLUMNS))::-:)}%{%G%}<%1(l.%2(l.FAIL.PASS).FAIL)> " zsh -dfis <<<exit
function _p9k_prompt_overflow_bug() {
[[ $ZSH_PATCHLEVEL =~ '^zsh-5\.4\.2-([0-9]+)-' ]] && return $(( match[1] < 159 ))
[[ $ZSH_PATCHLEVEL =~ '^zsh-5\.7\.1-([0-9]+)-' ]] && return $(( match[1] >= 50 ))
- is-at-least 5.5 && ! is-at-least 5.7.2
+ [[ $ZSH_VERSION == 5.<5-7>* && $ZSH_VERSION != 5.7.<2->* ]]
}
typeset -g _p9k__param_pat
@@ -7117,6 +7138,14 @@ _p9k_init_vars() {
typeset -gi _p9k__restore_prompt_fd
typeset -gi _p9k__redraw_fd
typeset -gi _p9k__can_hide_cursor=$(( $+terminfo[civis] && $+terminfo[cnorm] ))
+ if (( _p9k__can_hide_cursor )); then
+ # See https://github.com/romkatv/powerlevel10k/issues/1699
+ if [[ $terminfo[cnorm] == *$'\e[?25h'(|'\e'*) ]]; then
+ typeset -g _p9k__cnorm=$'\e[?25h'
+ else
+ typeset -g _p9k__cnorm=$terminfo[cnorm]
+ fi
+ fi
typeset -gi _p9k__cursor_hidden
typeset -gi _p9k__non_hermetic_expansion
typeset -g _p9k__time
@@ -7448,6 +7477,8 @@ _p9k_init_params() {
_p9k_declare -b POWERLEVEL9K_DOTNET_VERSION_PROJECT_ONLY 1
_p9k_declare -b POWERLEVEL9K_GO_VERSION_PROJECT_ONLY 1
_p9k_declare -b POWERLEVEL9K_RUST_VERSION_PROJECT_ONLY 1
+ _p9k_declare -b POWERLEVEL9K_PERLBREW_PROJECT_ONLY 1
+ _p9k_declare -b POWERLEVEL9K_PERLBREW_SHOW_PREFIX 0
_p9k_declare -b POWERLEVEL9K_JAVA_VERSION_PROJECT_ONLY 0
_p9k_declare -b POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW 0
_p9k_declare -a POWERLEVEL9K_NODENV_SOURCES -- shell local global
@@ -7631,7 +7662,7 @@ function _p9k_on_widget_zle-keymap-select() { _p9k_check_visual_mode; __p9k_rese
function _p9k_on_widget_overwrite-mode() { _p9k_check_visual_mode; __p9k_reset_state=2; }
function _p9k_on_widget_vi-replace() { _p9k_check_visual_mode; __p9k_reset_state=2; }
-if is-at-least 5.3; then
+if [[ $ZSH_VERSION == (5.<3->*|<6->.*) ]]; then
function _p9k_check_visual_mode() {
[[ ${KEYMAP:-} == vicmd ]] || return 0
local region=${${REGION_ACTIVE:-0}/2/1}
@@ -7650,7 +7681,7 @@ function _p9k_on_widget_deactivate-region() { _p9k_check_visual_mode; }
function _p9k_on_widget_zle-line-init() {
(( _p9k__cursor_hidden )) || return 0
_p9k__cursor_hidden=0
- echoti cnorm
+ print -rn -- $_p9k__cnorm
}
function _p9k_on_widget_zle-line-finish() {
@@ -7808,7 +7839,7 @@ function _p9k_wrap_widgets() {
typeset -gir __p9k_widgets_wrapped=1
local -a widget_list
- if is-at-least 5.3; then
+ if [[ $ZSH_VERSION == (5.<3->*|<6->.*) ]]; then
local -aU widget_list=(
zle-line-pre-redraw
zle-line-init
@@ -8154,7 +8185,7 @@ _p9k_init_prompt() {
_p9k_all_params_eq '_POWERLEVEL9K_*WHITESPACE_BETWEEN_RIGHT_SEGMENTS' ' ' &&
_p9k_all_params_eq '_POWERLEVEL9K_*RIGHT_RIGHT_WHITESPACE' ' ' &&
_p9k_all_params_eq '_POWERLEVEL9K_*RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL' '' &&
- ! is-at-least 5.7.2; then
+ [[ $ZSH_VERSION != (5.7.<2->*|5.<8->*|<6->.*) ]]; then
_p9k_emulate_zero_rprompt_indent=1
_p9k_prompt_prefix_left+='${${:-${_p9k__real_zle_rprompt_indent:=$ZLE_RPROMPT_INDENT}${ZLE_RPROMPT_INDENT::=1}${_p9k__ind::=0}}+}'
_p9k_line_suffix_right[-1]='${_p9k__sss:+${_p9k__sss% }%E}}'
@@ -8274,9 +8305,10 @@ _p9k_init_toolbox() {
local name=(${(Q)${${(@M)${(f)"$(</run/.containerenv)"}:#name=*}#name=}})
[[ ${#name} -eq 1 && -n ${name[1]} ]] || return 0
typeset -g P9K_TOOLBOX_NAME=${name[1]}
- elif [[ -n $DISTROBOX_ENTER_PATH && -n $NAME ]]; then
+ elif [[ -n $DISTROBOX_ENTER_PATH ]]; then
local name=${(%):-%m}
- if [[ $name == $NAME* ]]; then
+ # $NAME can be empty, see https://github.com/romkatv/powerlevel10k/pull/1916.
+ if [[ -n $name && $name == $NAME* ]]; then
typeset -g P9K_TOOLBOX_NAME=$name
fi
fi
@@ -8291,7 +8323,7 @@ _p9k_must_init() {
[[ $sig == $_p9k__param_sig ]] && return 1
_p9k_deinit
fi
- _p9k__param_pat=$'v134\1'${(q)ZSH_VERSION}$'\1'${(q)ZSH_PATCHLEVEL}$'\1'
+ _p9k__param_pat=$'v136\1'${(q)ZSH_VERSION}$'\1'${(q)ZSH_PATCHLEVEL}$'\1'
_p9k__param_pat+=$__p9k_force_term_shell_integration$'\1'
_p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\1'
_p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1'
@@ -8824,7 +8856,7 @@ typeset -gi __p9k_configured=0
typeset -gri __p9k_instant_prompt_disabled=1
# `typeset -g` doesn't roundtrip in zsh prior to 5.4.
-if is-at-least 5.4; then
+if [[ $ZSH_VERSION == (5.<4->*|<6->.*) ]]; then
typeset -gri __p9k_dumps_enabled=1
else
typeset -gri __p9k_dumps_enabled=0
@@ -9236,6 +9268,8 @@ if [[ $__p9k_dump_file != $__p9k_instant_prompt_dump_file && -n $__p9k_instant_p
zf_rm -f -- $__p9k_instant_prompt_dump_file{,.zwc} 2>/dev/null
fi
+unset VSCODE_SHELL_INTEGRATION
+
_p9k_init_ssh
_p9k_init_toolbox
prompt_powerlevel9k_setup