diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/configure.zsh | 20 | ||||
-rw-r--r-- | internal/p10k.zsh | 29 | ||||
-rw-r--r-- | internal/wizard.zsh | 68 |
3 files changed, 84 insertions, 33 deletions
diff --git a/internal/configure.zsh b/internal/configure.zsh index 9c92c233..4fb7cb6e 100644 --- a/internal/configure.zsh +++ b/internal/configure.zsh @@ -1,5 +1,7 @@ -typeset -gr __p9k_wizard_columns=51 -typeset -gr __p9k_wizard_lines=12 +# Fewer than 47 columns will probably work. Haven't tried it. +typeset -gr __p9k_wizard_columns=47 +# The bottleneck is ask_tails with nerd fonts. Everything else works fine with 12 lines. +typeset -gr __p9k_wizard_lines=14 typeset -gr __p9k_zd=${ZDOTDIR:-$HOME} typeset -gr __p9k_zd_u=${${${(q)__p9k_zd}/#(#b)${(q)HOME}(|\/*)/'~'$match[1]}//\%/%%} typeset -gr __p9k_zshrc=${${:-$__p9k_zd/.zshrc}:A} @@ -19,10 +21,20 @@ function _p9k_can_configure() { [[ -o multibyte ]] || { $0_error "multibyte option is not set"; return 1 } [[ -e $__p9k_zd ]] || { $0_error "$__p9k_zd_u does not exist"; return 1 } [[ -d $__p9k_zd ]] || { $0_error "$__p9k_zd_u is not a directory"; return 1 } - [[ -w $__p9k_zd ]] || { $0_error "$__p9k_zd_u is not writable"; return 1 } [[ ! -d $__p9k_cfg_path ]] || { $0_error "$__p9k_cfg_path_u is a directory"; return 1 } [[ ! -d $__p9k_zshrc ]] || { $0_error "$__p9k_zshrc_u is a directory"; return 1 } + local dir=${__p9k_cfg_path:h} + while [[ ! -e $dir && $dir != ${dir:h} ]]; do dir=${dir:h}; done + if [[ ! -d $dir ]]; then + $0_error "cannot create $__p9k_cfg_path_u because ${dir//\%/%%} is not a directory" + return 1 + fi + if [[ ! -w $dir ]]; then + $0_error "cannot create $__p9k_cfg_path_u because ${dir//\%/%%} is readonly" + return 1 + fi + [[ ! -e $__p9k_cfg_path || -f $__p9k_cfg_path || -h $__p9k_cfg_path ]] || { $0_error "$__p9k_cfg_path_u is a special file" return 1 @@ -44,7 +56,7 @@ function _p9k_can_configure() { done (( LINES >= __p9k_wizard_lines && COLUMNS >= __p9k_wizard_columns )) || { - $0_error "terminal size too small; must be at least $__p9k_wizard_columns x $__p9k_wizard_lines" + $0_error "terminal size too small; must be at least $__p9k_wizard_columns columns by $__p9k_wizard_lines lines" return 1 } [[ -t 0 && -t 1 ]] || { $0_error "no TTY"; return 2 } diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 24d756ac..0820a5f4 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -1384,7 +1384,7 @@ _p9k_prompt_battery_set_args() { ;; esac - (( bat_percent >= _POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD )) && return + (( bat_percent >= _POWERLEVEL9K_BATTERY_${state}_HIDE_ABOVE_THRESHOLD )) && return local msg="$bat_percent%%" [[ $_POWERLEVEL9K_BATTERY_VERBOSE == 1 && -n $remain ]] && msg+=" ($remain)" @@ -5381,8 +5381,8 @@ function _p9k_prompt_net_iface_async() { typeset -a iface2ip ips ifaces if (( $+commands[ifconfig] )); then for line in ${(f)"$(command ifconfig 2>/dev/null)"}; do - if [[ $line == (#b)([^[:space:]]##):[[:space:]]##flags=(<->)'<'* ]]; then - [[ $match[2] == *[13579] ]] && iface=$match[1] || iface= + if [[ $line == (#b)([^[:space:]]##):[[:space:]]##flags=([[:xdigit:]]##)'<'* ]]; then + [[ $match[2] == *[13579bdfBDF] ]] && iface=$match[1] || iface= elif [[ -n $iface && $line == (#b)[[:space:]]##inet[[:space:]]##([0-9.]##)* ]]; then iface2ip+=($iface $match[1]) iface= @@ -6913,6 +6913,7 @@ _p9k_init_params() { esac local state for state in CHARGED CHARGING LOW DISCONNECTED; do + _p9k_declare -i POWERLEVEL9K_BATTERY_${state}_HIDE_ABOVE_THRESHOLD $_POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD local var=POWERLEVEL9K_BATTERY_${state}_STAGES case $parameters[$var] in scalar*) eval "typeset -ga _$var=(${(@qq)${(@s::)${(g::)${(P)var}}}})";; @@ -7034,7 +7035,7 @@ _p9k_init_params() { _p9k_declare -s POWERLEVEL9K_IP_INTERFACE "" : ${_POWERLEVEL9K_IP_INTERFACE:='.*'} _p9k_segment_in_use ip || _POWERLEVEL9K_IP_INTERFACE= - _p9k_declare -s POWERLEVEL9K_VPN_IP_INTERFACE "(wg|(.*tun))[0-9]*" + _p9k_declare -s POWERLEVEL9K_VPN_IP_INTERFACE "(gpd|wg|(.*tun))[0-9]*" : ${_POWERLEVEL9K_VPN_IP_INTERFACE:='.*'} _p9k_segment_in_use vpn_ip || _POWERLEVEL9K_VPN_IP_INTERFACE= _p9k_declare -b POWERLEVEL9K_VPN_IP_SHOW_ALL 0 @@ -7285,6 +7286,10 @@ function _p9k_on_widget_zle-line-finish() { _p9k__line_finished='%{%}' } +function _p9k_on_widget_send-break() { + _p9k_on_widget_zle-line-finish int +} + # Usage example: _p9k_display_segment 58 _p9k__1rkubecontext hide function _p9k_display_segment() { [[ $_p9k__display_v[$1] == $3 ]] && return @@ -7376,6 +7381,14 @@ function _p9k_widget() { return res } +function _p9k_widget_send-break() { + (( ! __p9k_enabled )) || [[ $CONTEXT != start ]] || { + _p9k_widget_hook send-break "$@" + } + local f=${widgets[._p9k_orig_send-break]:-} + [[ -z $f ]] || zle ._p9k_orig_send-break -- "$@" +} + typeset -gi __p9k_widgets_wrapped=0 function _p9k_wrap_widgets() { @@ -7394,6 +7407,7 @@ function _p9k_wrap_widgets() { visual-line-mode deactivate-region clear-screen + send-break $_POWERLEVEL9K_HOOK_WIDGETS ) else @@ -7410,6 +7424,7 @@ function _p9k_wrap_widgets() { zle-line-finish zle-history-line-set zle-keymap-select + send-break $_POWERLEVEL9K_HOOK_WIDGETS ${${${(f)"$(<$tmp)"}##* }:#(*\"|.*)} ) @@ -7419,7 +7434,9 @@ function _p9k_wrap_widgets() { fi local widget for widget in $widget_list; do - functions[_p9k_widget_$widget]='_p9k_widget '${(q)widget}' "$@"' + if (( ! $+functions[_p9k_widget_$widget] )); then + functions[_p9k_widget_$widget]='_p9k_widget '${(q)widget}' "$@"' + fi # The leading dot is to work around bugs in zsh-syntax-highlighting. zle -A $widget ._p9k_orig_$widget zle -N $widget _p9k_widget_$widget @@ -7786,7 +7803,7 @@ _p9k_must_init() { [[ $sig == $_p9k__param_sig ]] && return 1 _p9k_deinit fi - _p9k__param_pat=$'v104\1'${(q)ZSH_VERSION}$'\1'${(q)ZSH_PATCHLEVEL}$'\1' + _p9k__param_pat=$'v106\1'${(q)ZSH_VERSION}$'\1'${(q)ZSH_PATCHLEVEL}$'\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' _p9k__param_pat+=$'$GITSTATUS_CACHE_DIR\1$GITSTATUS_AUTO_INSTALL\1${ZLE_RPROMPT_INDENT:-1}\1' diff --git a/internal/wizard.zsh b/internal/wizard.zsh index 4ef373a7..cd62a384 100644 --- a/internal/wizard.zsh +++ b/internal/wizard.zsh @@ -281,6 +281,7 @@ function quit() { } local screen_widgets=() +local -i max_priority local -i prompt_idx local choice @@ -289,6 +290,7 @@ function add_widget() { shift local render="${(j: :)${(@q)*}}" screen_widgets+=("$priority" "$render") + (( priority <= max_priority )) || max_priority=priority } function render_screen_pass() { @@ -327,7 +329,7 @@ function render_screen() { else break fi - while (( (COLUMNS > 88 ? 88 : COLUMNS) == wizard_columns && LINES == wizard_lines )); do + while (( get_columns() == wizard_columns && LINES == wizard_lines )); do sleep 1 done done @@ -356,7 +358,7 @@ function render_screen() { flowing -c %1FNot enough vertical space.%f print flowing Make terminal window %Btaller%b or press %BCtrl-C%b to abort Powerlevel10k configuration wizard. - while (( (COLUMNS > 88 ? 88 : COLUMNS) == wizard_columns && LINES == wizard_lines )); do + while (( get_columns() == wizard_columns && LINES == wizard_lines )); do sleep 1 done done @@ -389,6 +391,7 @@ function ask() { local -i lines columns wizard_lines wizard_columns add_widget 0 print -P "(q) Quit and do nothing." add_widget 0 print + add_widget $((max_priority + 1)) add_widget 0 print -P "%BChoice [${choices}q]: %b" while true; do =true @@ -404,6 +407,7 @@ function ask() { fi if [[ $choices == *$choice* ]]; then screen_widgets=() + max_priority=0 prompt_idx=0 return fi @@ -501,19 +505,19 @@ function install_font() { clear case $terminal in Termux) - mkdir -p ~/.termux || quit -c + command mkdir -p -- ~/.termux || quit -c run_command "Downloading %BMesloLGS NF Regular.ttf%b" \ curl -fsSL -o ~/.termux/font.ttf "$font_base_url/MesloLGS%20NF%20Regular.ttf" run_command "Reloading %BTermux%b settings" termux-reload-settings ;; iTerm2) - mkdir -p ~/Library/Fonts || quit -c + command mkdir -p -- ~/Library/Fonts || quit -c local style for style in Regular Bold Italic 'Bold Italic'; do local file="MesloLGS NF ${style}.ttf" run_command "Downloading %B$file%b" \ curl -fsSL -o ~/Library/Fonts/$file.tmp "$font_base_url/${file// /%20}" - zf_mv -f -- ~/Library/Fonts/$file{.tmp,} || quit -c + command mv -f -- ~/Library/Fonts/$file{.tmp,} || quit -c done print -nP -- "Changing %BiTerm2%b settings ..." local size=$iterm2_font_size @@ -666,13 +670,13 @@ function ask_diamond() { add_widget 0 print add_widget 0 flowing -c -- "---> \uE0B2\uE0B0 <---" add_widget 0 print - add_widget 1 + add_widget 3 add_widget 0 print -P "%B(y) Yes.%b" add_widget 0 print add_widget 1 add_widget 0 print -P "%B(n) No.%b" add_widget 0 print - add_widget 1 + add_widget 2 if (( can_install_font )); then extra+=r add_widget 0 print -P "(r) Restart from the beginning." @@ -694,10 +698,13 @@ function ask_lock() { add_widget 0 print add_widget 0 flowing -c -- "---> $1 <---" add_widget 0 print + add_widget 3 add_widget 0 print -P "%B(y) Yes.%b" add_widget 0 print + add_widget 1 add_widget 0 print -P "%B(n) No.%b" add_widget 0 print + add_widget 2 add_widget 0 print -P "(r) Restart from the beginning." ask ynr case $choice in @@ -714,10 +721,13 @@ function ask_python() { add_widget 0 print -P "" add_widget 0 flowing -c -- "---> \uE63C <---" add_widget 0 print -P "" + add_widget 3 add_widget 0 print -P "%B(y) Yes.%b" add_widget 0 print -P "" + add_widget 1 add_widget 0 print -P "%B(n) No.%b" add_widget 0 print -P "" + add_widget 2 add_widget 0 print -P "(r) Restart from the beginning." ask ynr case $choice in @@ -733,10 +743,13 @@ function ask_arrow() { add_widget 0 print -P "" add_widget 0 flowing -c -- "---> \u276F\u276E <---" add_widget 0 print -P "" + add_widget 3 add_widget 0 print -P "%B(y) Yes.%b" add_widget 0 print -P "" + add_widget 1 add_widget 0 print -P "%B(n) No.%b" add_widget 0 print -P "" + add_widget 2 add_widget 0 print -P "(r) Restart from the beginning." ask ynr case $choice in @@ -753,10 +766,13 @@ function ask_debian() { add_widget 0 print -P "" add_widget 0 flowing -c -- "---> \uF306 <---" add_widget 0 print -P "" + add_widget 3 add_widget 0 print -P "%B(y) Yes.%b" add_widget 0 print -P "" + add_widget 1 add_widget 0 print -P "%B(n) No.%b" add_widget 0 print -P "" + add_widget 2 add_widget 0 print -P "(r) Restart from the beginning." ask ynr case $choice in @@ -787,10 +803,13 @@ function ask_icon_padding() { add_widget 0 print -P "" add_widget 0 flowing -c -- "---> $text <---" add_widget 0 print -P "" + add_widget 3 add_widget 0 flowing +c -i 5 "%B(y) Yes." Icons are very close to the crosses but there is "%b%2Fno overlap%f%B.%b" add_widget 0 print -P "" + add_widget 1 add_widget 0 flowing +c -i 5 "%B(n) No." Some icons "%b%2Foverlap%f%B" neighbouring crosses.%b add_widget 0 print -P "" + add_widget 2 add_widget 0 print -P "(r) Restart from the beginning." ask ynr case $choice in @@ -1392,16 +1411,16 @@ function ask_empty_line() { add_widget 0 print -P "%B(1) Compact.%b" add_widget 0 print add_widget 1 - add_widget 0 print_prompt - add_widget 0 print_prompt + add_prompt_n + add_prompt_n add_widget 0 print add_widget 2 add_widget 0 print -P "%B(2) Sparse.%b" add_widget 0 print add_widget 1 - add_widget 0 print_prompt + add_prompt_n add_widget 0 print - add_widget 0 print_prompt + add_prompt_n add_widget 0 print add_widget 2 add_widget 0 print -P "(r) Restart from the beginning." @@ -1437,27 +1456,24 @@ function ask_instant_prompt() { add_widget 1 add_widget 0 print add_widget 2 - add_widget 0 flowing +c -i 5 "%B(1) Off.%b" Disable instant prompt. Choose this if you\'ve \ - tried instant prompt and found it incompatible with your zsh configuration files. + add_widget 0 flowing +c -i 5 "%B(1) Verbose (recommended).%b" add_widget 0 print add_widget 1 - add_widget 0 flowing +c -i 5 "%B(2) Quiet.%b" Enable instant prompt and %Bdon\'t print \ - warnings%b when detecting console output during zsh initialization. Choose this if you\'ve \ - read and understood instant prompt documentation. + add_widget 0 flowing +c -i 5 "%B(2) Quiet.%b" Choose this if you\'ve read and understood \ + instant prompt documentation. add_widget 0 print add_widget 1 - add_widget 0 flowing +c -i 5 "%B(3) Verbose.%b" Enable instant prompt and %Bprint a warning%b \ - when detecting console output during zsh initialization. %BChoose this if you\'ve never tried \ - instant prompt, haven\'t seen the warning, or if you are unsure what this all means%b. + add_widget 0 flowing +c -i 5 "%B(3) Off.%b" Choose this if you\'ve tried instant prompt \ + and found it incompatible with your zsh configuration files. add_widget 0 print add_widget 2 add_widget 0 print -P "(r) Restart from the beginning." ask 123r case $choice in r) return 1;; - 1) instant_prompt=off; options+=instant_prompt=off;; + 1) instant_prompt=verbose; options+=instant_prompt=verbose;; 2) instant_prompt=quiet; options+=instant_prompt=quiet;; - 3) instant_prompt=verbose; options+=instant_prompt=verbose;; + 3) instant_prompt=off; options+=instant_prompt=off;; esac return 0 } @@ -1574,7 +1590,11 @@ function ask_zshrc_edit() { add_widget 0 print -P "" add_widget 1 local modifiable=y - if [[ -e $__p9k_zshrc && ! -w $__p9k_zshrc ]]; then + if [[ ! -w $__p9k_zd ]]; then + modifiable= + add_widget 0 flowing -c %3FWARNING:%f %2F${__p9k_zd_u//\\/\\\\}%f %3Fis readonly.%f + add_widget 0 print -P "" + elif [[ -e $__p9k_zshrc && ! -w $__p9k_zshrc ]]; then local -a stat zstat -A stat +uid -- $__p9k_zshrc || quit -c if (( stat[1] == EUID )); then @@ -1859,6 +1879,8 @@ function generate_config() { header+=$line header+=$'.\n# Type `p10k configure` to generate another config.\n#' + command mkdir -p -- ${__p9k_cfg_path:h} || return + if [[ -e $__p9k_cfg_path ]]; then unlink $__p9k_cfg_path || return fi @@ -1898,7 +1920,7 @@ fi" || return [[ ! -f ${(%)__p9k_cfg_path_u} ]] || source ${(%)__p9k_cfg_path_u}" || return fi (( writable )) || chmod u-w -- $tmp || return - zf_mv -f -- $tmp $__p9k_zshrc || return + command mv -f -- $tmp $__p9k_zshrc || return } always { zf_rm -f -- $tmp } |