diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/icons.zsh | 2 | ||||
-rw-r--r-- | internal/p10k.zsh | 76 | ||||
-rwxr-xr-x | internal/wizard.zsh | 110 |
3 files changed, 93 insertions, 95 deletions
diff --git a/internal/icons.zsh b/internal/icons.zsh index d41319bc..919eafca 100644 --- a/internal/icons.zsh +++ b/internal/icons.zsh @@ -1,7 +1,7 @@ typeset -gA icons function _p9k_init_icons() { - [[ $+_p9k__icon_mode == 1 && $_p9k__icon_mode == $POWERLEVEL9K_MODE/$POWERLEVEL9K_LEGACY_ICON_SPACING ]] && return + [[ $_p9k__icon_mode == $POWERLEVEL9K_MODE/$POWERLEVEL9K_LEGACY_ICON_SPACING/$POWERLEVEL9K_ICON_PADDING ]] && return typeset -g _p9k__icon_mode=$POWERLEVEL9K_MODE/$POWERLEVEL9K_LEGACY_ICON_SPACING/$POWERLEVEL9K_ICON_PADDING if [[ $POWERLEVEL9K_LEGACY_ICON_SPACING == true ]]; then diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 3e54608a..3dbf02bf 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -432,20 +432,13 @@ _p9k_cache_stat_get() { fi if (( $+commands[md5] )); then - local -a md5=(md5) + _p9k__cache_stat_fprint="$(md5 -- $* 2>&1)" elif (( $+commands[md5sum] )); then - local -a md5=(md5sum -b) + _p9k__cache_stat_fprint="$(md5sum -b -- $* 2>&1)" else return 1 fi - local fprint - for f; do - if fprint="$($md5 $f 2>/dev/null)"; then - _p9k__cache_stat_fprint+="${(q)fprint} " - fi - done - local meta_key=$_p9k__cache_key if _p9k_cache_ephemeral_get $0 $label fprint "$@" "$_p9k__cache_stat_fprint"; then _p9k__cache_fprint_key=$_p9k__cache_key @@ -1089,7 +1082,7 @@ function _p9k_prompt_segment() { "_p9k_${_p9k__prompt_side}_prompt_segment" "$@" function p9k_prompt_segment() { p10k segment "$@" } function _p9k_python_version() { - _p9k_cached_cmd_stdout_stderr python --version || return + _p9k_cached_cmd 1 python --version || return [[ $_p9k__ret == (#b)Python\ ([[:digit:].]##)* ]] && _p9k__ret=$match[1] } @@ -2022,7 +2015,7 @@ _p9k_prompt_docker_machine_init() { ################################################################ # GO prompt prompt_go_version() { - _p9k_cached_cmd_stdout go version || return + _p9k_cached_cmd 0 go version || return [[ $_p9k__ret == (#b)*go([[:digit:].]##)* ]] || return local v=$match[1] if (( _POWERLEVEL9K_GO_VERSION_PROJECT_ONLY )); then @@ -2247,26 +2240,19 @@ _p9k_prompt_load_sync() { _p9k_worker_reply $REPLY } -function _p9k_cached_cmd_stdout() { - local cmd=${commands[$1]:A} - [[ -n $cmd ]] || return - shift - if ! _p9k_cache_stat_get $0" ${(q)*}" $cmd; then - local out - out="$($cmd "$@" 2>/dev/null)" - _p9k_cache_stat_set $(( ! $? )) "$out" - fi - (( $_p9k__cache_val[1] )) || return - _p9k__ret=$_p9k__cache_val[2] -} - -function _p9k_cached_cmd_stdout_stderr() { - local cmd=${commands[$1]:A} +# Usage: _p9k_cached_cmd <0|1> <cmd> [args...] +# +# The first argument says whether to capture stderr (1) or ignore it (0). +function _p9k_cached_cmd() { + local cmd=$commands[$2] [[ -n $cmd ]] || return - shift if ! _p9k_cache_stat_get $0" ${(q)*}" $cmd; then local out - out="$($cmd "$@" 2>&1)" # this line is the only diff with _p9k_cached_cmd_stdout + if (( $1 )); then + out="$($cmd "${@:3}" 2>&1)" + else + out="$($cmd "${@:3}" 2>/dev/null)" + fi _p9k_cache_stat_set $(( ! $? )) "$out" fi (( $_p9k__cache_val[1] )) || return @@ -2279,7 +2265,7 @@ prompt_node_version() { if (( _POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY )); then _p9k_upglob package.json && return fi - _p9k_cached_cmd_stdout node --version && [[ $_p9k__ret == v?* ]] || return + _p9k_cached_cmd 0 node --version && [[ $_p9k__ret == v?* ]] || return _p9k_prompt_segment "$0" "green" "white" 'NODE_ICON' 0 '' "${_p9k__ret#v}" } @@ -2372,10 +2358,10 @@ _p9k_nvm_ls_current() { local nvm_dir=${NVM_DIR:A} if [[ -n $nvm_dir && $node_path == $nvm_dir/versions/io.js/* ]]; then - _p9k_cached_cmd_stdout iojs --version || return + _p9k_cached_cmd 0 iojs --version || return _p9k__ret=iojs-v${_p9k__ret#v} elif [[ -n $nvm_dir && $node_path == $nvm_dir/* ]]; then - _p9k_cached_cmd_stdout node --version || return + _p9k_cached_cmd 0 node --version || return _p9k__ret=v${_p9k__ret#v} else _p9k__ret=system @@ -2400,7 +2386,7 @@ _p9k_prompt_nvm_init() { # Segment to display NodeEnv prompt_nodeenv() { local msg - if (( _POWERLEVEL9K_NODEENV_SHOW_NODE_VERSION )) && _p9k_cached_cmd_stdout node --version; then + if (( _POWERLEVEL9K_NODEENV_SHOW_NODE_VERSION )) && _p9k_cached_cmd 0 node --version; then msg="${_p9k__ret//\%/%%} " fi msg+="$_POWERLEVEL9K_NODEENV_LEFT_DELIMITER${${NODE_VIRTUAL_ENV:t}//\%/%%}$_POWERLEVEL9K_NODEENV_RIGHT_DELIMITER" @@ -2488,7 +2474,7 @@ prompt_dotnet_version() { if (( _POWERLEVEL9K_DOTNET_VERSION_PROJECT_ONLY )); then _p9k_upglob 'project.json|global.json|packet.dependencies|*.csproj|*.fsproj|*.xproj|*.sln' && return fi - _p9k_cached_cmd_stdout dotnet --version || return + _p9k_cached_cmd 0 dotnet --version || return _p9k_prompt_segment "$0" "magenta" "white" 'DOTNET_ICON' 0 '' "$_p9k__ret" } @@ -2512,7 +2498,7 @@ prompt_php_version() { if (( _POWERLEVEL9K_PHP_VERSION_PROJECT_ONLY )); then _p9k_upglob 'composer.json|*.php' && return fi - _p9k_cached_cmd_stdout php --version || return + _p9k_cached_cmd 0 php --version || return [[ $_p9k__ret == (#b)(*$'\n')#'PHP '([[:digit:].]##)* ]] || return local v=$match[2] _p9k_prompt_segment "$0" "fuchsia" "grey93" 'PHP_ICON' 0 '' "${v//\%/%%}" @@ -4167,7 +4153,7 @@ _p9k_prompt_openfoam_init() { ################################################################ # Segment to display Swift version prompt_swift_version() { - _p9k_cached_cmd_stdout swift --version || return + _p9k_cached_cmd 0 swift --version || return [[ $_p9k__ret == (#b)[^[:digit:]]#([[:digit:].]##)* ]] || return _p9k_prompt_segment "$0" "magenta" "white" 'SWIFT_ICON' 0 '' "${match[1]//\%/%%}" } @@ -4296,12 +4282,18 @@ prompt_java_version() { if (( _POWERLEVEL9K_JAVA_VERSION_PROJECT_ONLY )); then _p9k_upglob 'pom.xml|build.gradle.kts|build.sbt|deps.edn|project.clj|build.boot|*.(java|class|jar|gradle|clj|cljc)' && return fi - _p9k_cached_cmd_stdout_stderr java -fullversion || return - local v=$_p9k__ret - v=${${v#*\"}%\"*} - (( _POWERLEVEL9K_JAVA_VERSION_FULL )) || v=${v%%-*} - [[ -n $v ]] || return - _p9k_prompt_segment "$0" "red" "white" "JAVA_ICON" 0 '' "${v//\%/%%}" + + local java=$commands[java] + if ! _p9k_cache_stat_get $0 $java ${JAVA_HOME:+$JAVA_HOME/release}; then + local v + v="$(java -fullversion 2>&1)" || v= + v=${${v#*\"}%\"*} + (( _POWERLEVEL9K_JAVA_VERSION_FULL )) || v=${v%%-*} + _p9k_cache_stat_set "${v//\%/%%}" + fi + + [[ -n $_p9k__cache_val[1] ]] || return + _p9k_prompt_segment "$0" "red" "white" "JAVA_ICON" 0 '' $_p9k__cache_val[1] } _p9k_prompt_java_version_init() { @@ -7497,7 +7489,7 @@ _p9k_must_init() { [[ $sig == $_p9k__param_sig ]] && return 1 _p9k_deinit fi - _p9k__param_pat=$'v74\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1' + _p9k__param_pat=$'v76\1'${ZSH_VERSION}$'\1'${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+=$'$DEFAULT_USER\1${ZLE_RPROMPT_INDENT:-1}\1$P9K_SSH\1$__p9k_ksh_arrays\1' diff --git a/internal/wizard.zsh b/internal/wizard.zsh index 09977a68..2c1d9d41 100755 --- a/internal/wizard.zsh +++ b/internal/wizard.zsh @@ -19,7 +19,7 @@ fi local -ri force local -r font_base_url='https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts' -local -ri wizard_columns=$((COLUMNS < 80 ? COLUMNS : 80)) +local -ri wizard_columns=$((COLUMNS < 83 ? COLUMNS : 83)) local -ri prompt_indent=2 @@ -46,33 +46,36 @@ local -r slanted_bar='\uE0BD' local -r cursor='%1{\e[07m \e[27m%}' +local -r time_24h='16:23:42' +local -r time_12h='04:23:42 PM' + local -ra lean_left=( - '%$frame_color[$color]F╭─ ' '${extra_icons[1]:+$extra_icons[1] }%31F$extra_icons[2]%B%39F~%b%31F/%B%39Fsrc%b%f $prefixes[1]%76F$extra_icons[3]master%f ' + '%$frame_color[$color]F╭─ ' '${extra_icons[1]:+%B%f$extra_icons[1] %b}%31F$extra_icons[2]%B%39F~%b%31F/%B%39Fsrc%b%f $prefixes[1]%76F$extra_icons[3]master%f ' '%$frame_color[$color]F╰─' '%76F$prompt_char%f ${buffer:-$cursor}' ) local -ra lean_right=( - ' $prefixes[2]%101F$extra_icons[4]5s%f${show_time:+ $prefixes[3]%66F$extra_icons[5]16:23:42%f}' ' %$frame_color[$color]F─╮%f' + ' $prefixes[2]%101F$extra_icons[4]5s%f${time:+ $prefixes[3]%66F$extra_icons[5]$time%f}' ' %$frame_color[$color]F─╮%f' '' ' %$frame_color[$color]F─╯%f' ) local -ra lean_8colors_left=( - '%$frame_color[$color]F╭─ ' '${extra_icons[1]:+$extra_icons[1] }%4F$extra_icons[2]%4F~/src%f $prefixes[1]%2F$extra_icons[3]master%f ' + '%$frame_color[$color]F╭─ ' '${extra_icons[1]:+%f$extra_icons[1] }%4F$extra_icons[2]%4F~/src%f $prefixes[1]%2F$extra_icons[3]master%f ' '%$frame_color[$color]F╰─' '%2F$prompt_char%f ${buffer:-$cursor}' ) local -ra lean_8colors_right=( - ' $prefixes[2]%3F$extra_icons[4]5s%f${show_time:+ $prefixes[3]%6F$extra_icons[5]16:23:42%f}' ' %$frame_color[$color]F─╮%f' + ' $prefixes[2]%3F$extra_icons[4]5s%f${time:+ $prefixes[3]%6F$extra_icons[5]$time%f}' ' %$frame_color[$color]F─╮%f' '' ' %$frame_color[$color]F─╯%f' ) local -ra classic_left=( - '%$frame_color[$color]F╭─' '%F{$bg_color[$color]}$left_tail%K{$bg_color[$color]} ${extra_icons[1]:+$extra_icons[1]%K{$bg_color[$color]\} %$sep_color[$color]F$left_subsep%f }%31F$extra_icons[2]%B%39F~%b%K{$bg_color[$color]}%31F/%B%39Fsrc%b%K{$bg_color[$color]} %$sep_color[$color]F$left_subsep%f %$prefix_color[$color]F$prefixes[1]%76F$extra_icons[3]master %k%$bg_color[$color]F$left_head%f' + '%$frame_color[$color]F╭─' '%F{$bg_color[$color]}$left_tail%K{$bg_color[$color]} ${extra_icons[1]:+%255F$extra_icons[1] %$sep_color[$color]F$left_subsep%f }%31F$extra_icons[2]%B%39F~%b%K{$bg_color[$color]}%31F/%B%39Fsrc%b%K{$bg_color[$color]} %$sep_color[$color]F$left_subsep%f %$prefix_color[$color]F$prefixes[1]%76F$extra_icons[3]master %k%$bg_color[$color]F$left_head%f' '%$frame_color[$color]F╰─' '%f ${buffer:-$cursor}' ) local -ra classic_right=( - '%$bg_color[$color]F$right_head%K{$bg_color[$color]}%f %$prefix_color[$color]F$prefixes[2]%101F5s $extra_icons[4]${show_time:+%$sep_color[$color]F$right_subsep %$prefix_color[$color]F$prefixes[3]%66F16:23:42 $extra_icons[5]}%k%F{$bg_color[$color]}$right_tail%f' '%$frame_color[$color]F─╮%f' + '%$bg_color[$color]F$right_head%K{$bg_color[$color]}%f %$prefix_color[$color]F$prefixes[2]%101F5s $extra_icons[4]${time:+%$sep_color[$color]F$right_subsep %$prefix_color[$color]F$prefixes[3]%66F$time $extra_icons[5]}%k%F{$bg_color[$color]}$right_tail%f' '%$frame_color[$color]F─╮%f' '' '%$frame_color[$color]F─╯%f' ) @@ -82,17 +85,17 @@ local -ra pure_left=( ) local -ra pure_right=( - '${pure_use_rprompt+%F{$pure_color[yellow]\}5s%f${show_time:+ }}${show_time:+%F{$pure_color[grey]\}16:23:42%f}' '' + '${pure_use_rprompt+%F{$pure_color[yellow]\}5s%f${time:+ }}${time:+%F{$pure_color[grey]\}$time%f}' '' '' '' ) local -ra rainbow_left=( - '%$frame_color[$color]F╭─' '%F{${${extra_icons[1]:+7}:-4}}$left_tail${extra_icons[1]:+%K{7\} $extra_icons[1] %K{4\}%7F$left_sep}%K{4}%254F $extra_icons[2]%B%255F~%b%K{4}%254F/%B%255Fsrc%b%K{4} %K{2}%4F$left_sep %0F$prefixes[1]$extra_icons[3]master %k%2F$left_head%f' + '%$frame_color[$color]F╭─' '%F{${${extra_icons[1]:+7}:-4}}$left_tail${extra_icons[1]:+%K{7\}%232F $extra_icons[1] %K{4\}%7F$left_sep}%K{4}%254F $extra_icons[2]%B%255F~%b%K{4}%254F/%B%255Fsrc%b%K{4} %K{2}%4F$left_sep %0F$prefixes[1]$extra_icons[3]master %k%2F$left_head%f' '%$frame_color[$color]F╰─' '%f ${buffer:-$cursor}' ) local -ra rainbow_right=( - '%3F$right_head%K{3} %0F$prefixes[2]5s $extra_icons[4]%3F${show_time:+%7F$right_sep%K{7\} %0F$prefixes[3]16:23:42 $extra_icons[5]%7F}%k$right_tail%f' '%$frame_color[$color]F─╮%f' + '%3F$right_head%K{3} %0F$prefixes[2]5s $extra_icons[4]%3F${time:+%7F$right_sep%K{7\} %0F$prefixes[3]$time $extra_icons[5]%7F}%k$right_tail%f' '%$frame_color[$color]F─╮%f' '' '%$frame_color[$color]F─╯%f' ) @@ -609,21 +612,20 @@ function ask_debian() { done } -function ask_narrow_icons() { +function ask_icon_padding() { if [[ $POWERLEVEL9K_MODE == (powerline|compatible|ascii) ]]; then - cap_narrow_icons=0 + POWERLEVEL9K_ICON_PADDING=none return 0 fi local text="X" text+="%1F${icons[VCS_GIT_ICON]// }%fX" text+="%2F${icons[VCS_GIT_GITHUB_ICON]// }%fX" - text+="%3F${icons[DATE_ICON]// }%fX" - text+="%4F${icons[TIME_ICON]// }%fX" - text+="%5F${icons[RUBY_ICON]// }%fX" - text+="%6F${icons[HOME_ICON]// }%fX" - text+="%1F${icons[HOME_SUB_ICON]// }%fX" - text+="%2F${icons[FOLDER_ICON]// }%fX" - text+="%3F${icons[RAM_ICON]// }%fX" + text+="%3F${icons[TIME_ICON]// }%fX" + text+="%4F${icons[RUBY_ICON]// }%fX" + text+="%5F${icons[HOME_ICON]// }%fX" + text+="%6F${icons[HOME_SUB_ICON]// }%fX" + text+="%1F${icons[FOLDER_ICON]// }%fX" + text+="%2F${icons[RAM_ICON]// }%fX" while true; do clear flowing -c "%BDo all these icons %b%2Ffit between the crosses%f%B?%b" @@ -643,8 +645,8 @@ function ask_narrow_icons() { case $key in q) quit;; r) return 1;; - y) cap_narrow_icons=1; options+='small icons'; break;; - n) cap_narrow_icons=0; options+='large icons'; break;; + y) POWERLEVEL9K_ICON_PADDING=none; options+='small icons'; break;; + n) POWERLEVEL9K_ICON_PADDING=moderate; options+='large icons'; break;; esac done } @@ -751,10 +753,10 @@ function ask_charset() { left_frame=0 right_frame=0 POWERLEVEL9K_MODE=ascii + POWERLEVEL9K_ICON_PADDING=none cap_diamond=0 cap_python=0 cap_debian=0 - cap_narrow_icons=1 cap_lock=0 cap_arrow=0 break @@ -925,33 +927,48 @@ function ask_ornaments_color() { function ask_time() { if (( wizard_columns < 80 )) && [[ $style != pure ]]; then - show_time= + time= return 0 fi while true; do + local extra= clear flowing -c "%BShow current time?%b" print -P "" - print -P "%B(y) Yes.%b" + print -P "%B(1) No.%b" print -P "" - show_time=1 print_prompt + time= print_prompt print -P "" - print -P "%B(n) No.%b" + print -P "%B(2) 24-hour format.%b" print -P "" - show_time= print_prompt + time=$time_24h print_prompt print -P "" + if [[ $wizard_columns -ge 83 || $style == lean* || $POWERLEVEL9K_ICON_PADDING == none ]]; then + extra+=3 + print -P "%B(3) 12-hour format.%b" + print -P "" + time=$time_12h print_prompt + print -P "" + fi print -P "(r) Restart from the beginning." print -P "(q) Quit and do nothing." print -P "" local key= - read -k key${(%):-"?%BChoice [ynrq]: %b"} || quit -c + read -k key${(%):-"?%BChoice [12${extra}rq]: %b"} || quit -c case $key in q) quit;; r) return 1;; - y) show_time=1; options+=time; break;; - n) show_time=; break;; + 1) time=; break;; + 2) time=$time_24h; options+='24h time'; break;; + 3) + if [[ $extra == *3* ]]; then + time=$time_12h + options+='12h time' + break + fi + ;; esac done } @@ -1040,21 +1057,7 @@ function ask_extra_icons() { local branch_icon=${(g::)icons[VCS_BRANCH_ICON]} local duration_icon=${(g::)icons[EXECUTION_TIME_ICON]} local time_icon=${(g::)icons[TIME_ICON]} - if (( cap_narrow_icons )); then - os_icon=${os_icon// } - dir_icon=${dir_icon// } - vcs_icon=${vcs_icon// } - duration_icon=${duration_icon// } - time_icon=${time_icon// } - fi branch_icon=${branch_icon// } - if [[ $style == classic ]]; then - os_icon="%B%255F$os_icon%f%b" - elif [[ $style == rainbow ]]; then - os_icon="%B%F{232}$os_icon%f%b" - elif [[ $style != lean_8colors ]]; then - os_icon="%B%f$os_icon%b" - fi local few=('' '' '' '' '') local many=("$os_icon" "$dir_icon " "$vcs_icon $branch_icon " "$duration_icon " "$time_icon ") while true; do @@ -1776,9 +1779,7 @@ function generate_config() { else sub MODE $POWERLEVEL9K_MODE - if (( ! cap_narrow_icons )); then - sub ICON_PADDING moderate - fi + sub ICON_PADDING $POWERLEVEL9K_ICON_PADDING if [[ $POWERLEVEL9K_MODE == compatible ]]; then sub STATUS_ERROR_VISUAL_IDENTIFIER_EXPANSION "'х'" @@ -1945,8 +1946,11 @@ function generate_config() { done fi - if [[ -n $show_time ]]; then + if [[ -n $time ]]; then uncomment time + if [[ $time == $time_12h ]]; then + sub TIME_FORMAT "'%D{%I:%M:%S %p}'" + fi fi if (( num_lines == 1 )); then @@ -2057,10 +2061,11 @@ fi while true; do local instant_prompt=verbose zshrc_content= zshrc_backup= zshrc_backup_u= local -i zshrc_has_cfg=0 zshrc_has_instant_prompt=0 write_zshrc=0 - local POWERLEVEL9K_MODE= style= config_backup= config_backup_u= gap_char=' ' prompt_char='❯' - local left_subsep= right_subsep= left_tail= right_tail= left_head= right_head= show_time= + local POWERLEVEL9K_MODE= POWERLEVEL9K_ICON_PADDING=moderate style= config_backup= config_backup_u= + local gap_char=' ' prompt_char='❯' + local left_subsep= right_subsep= left_tail= right_tail= left_head= right_head= time= local -i num_lines=0 empty_line=0 color=2 left_frame=1 right_frame=1 transient_prompt=0 - local -i cap_diamond=0 cap_python=0 cap_debian=0 cap_narrow_icons=0 cap_lock=0 cap_arrow=0 + local -i cap_diamond=0 cap_python=0 cap_debian=0 cap_lock=0 cap_arrow=0 local -a extra_icons=('' '' '') local -a frame_color=(244 242 240 238) local -a color_name=(Lightest Light Dark Darkest) @@ -2144,8 +2149,9 @@ while true; do fi _p9k_init_icons + ask_icon_padding || continue + _p9k_init_icons - ask_narrow_icons || continue ask_style || continue ask_charset || continue ask_color_scheme || continue |