diff options
author | romkatv <roman.perepelitsa@gmail.com> | 2019-10-26 21:43:38 +0300 |
---|---|---|
committer | romkatv <roman.perepelitsa@gmail.com> | 2019-10-26 21:43:38 +0300 |
commit | 627d471fca17425ded63678bc84f81fbc84eaf70 (patch) | |
tree | c93dd440dc362e33d944916ab093fb457e118af8 /internal/wizard.zsh | |
parent | f17081ca98c9347a3e0ce1829337bfb909178ff9 (diff) |
improve instant prompt usability, update docs and add an option to the wizard to enable it
Diffstat (limited to 'internal/wizard.zsh')
-rwxr-xr-x | internal/wizard.zsh | 76 |
1 files changed, 59 insertions, 17 deletions
diff --git a/internal/wizard.zsh b/internal/wizard.zsh index f2e0b927..b483b4bb 100755 --- a/internal/wizard.zsh +++ b/internal/wizard.zsh @@ -1213,6 +1213,50 @@ function ask_empty_line() { done } +function ask_instant_prompt() { + autoload -Uz is-at-least + if ! is-at-least 5.4; then + instant_prompt=off + return + fi + if (( LINES < 24 )); then + local nl='' + else + local nl=$'\n' + fi + while true; do + clear + flowing -c "%BInstant Prompt Mode%b" + print -n $nl + flowing -c "$(href 'https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt')" + print -P "" + 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. + print -n $nl + 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 the documentation linked above. + print -n $nl + flowing +c -i 5 "%B(3) Verbose.%b" Enable instant prompt and %Bprint a warning%b when \ + detecting console output during zsh initialization. Choose this if you\'ve never tried \ + instant prompt, haven\'t seen the warning, or if you are unsure what this all means. + print -P "" + print -P "(r) Restart from the beginning." + print -P "(q) Quit and do nothing." + print -P "" + + local key= + read -k key${(%):-"?%BChoice [123rq]: %b"} || quit -c + case $key in + q) quit;; + r) return 1;; + 1) instant_prompt=off; break;; + 2) instant_prompt=quiet; break;; + 3) instant_prompt=verbose; break;; + esac + done +} + function ask_confirm() { while true; do clear @@ -1275,10 +1319,11 @@ function ask_zshrc_edit() { zshrc_backup= zshrc_backup_u= zshrc_has_cfg=0 - zshrc_has_pre=1 - zshrc_has_post=1 + zshrc_has_instant_prompt=0 write_zshrc=0 + [[ $instant_prompt == off ]] && zshrc_has_instant_prompt=1 + if [[ -e $__p9k_zshrc ]]; then zshrc_content="$(<$__p9k_zshrc)" || quit -c local lines=(${(f)zshrc_content}) @@ -1293,12 +1338,9 @@ function ask_zshrc_edit() { fi local pre='${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh' if [[ -n ${(@M)lines:#(#b)[^#]#([^[:IDENT:]]|)source[[:space:]]##($pre|\"$pre\")(|[[:space:]]*|'#'*)} ]]; then - zshrc_has_pre=1 + zshrc_has_instant_prompt=1 fi - if [[ -n ${(@M)lines:#(#b)[^#]#([^[:IDENT:]]|)p10k-instant-prompt-finalize([^[:IDENT:]]*|)} ]]; then - zshrc_has_post=1 - fi - (( zshrc_has_cfg && zshrc_has_pre && zshrc_has_post )) && return + (( zshrc_has_cfg && zshrc_has_instant_prompt )) && return fi while true; do @@ -1487,6 +1529,8 @@ function generate_config() { (( empty_line )) && sub PROMPT_ADD_NEWLINE true || sub PROMPT_ADD_NEWLINE false + sub INSTANT_PROMPT $instant_prompt + local header=${(%):-"# Generated by Powerlevel10k configuration wizard on %D{%Y-%m-%d at %H:%M %Z}."}$'\n' header+="# Based on romkatv/powerlevel10k/config/p10k-$style.zsh" if [[ $commands[sum] == ('/bin'|'/usr/bin'|'/usr/local/bin')'/sum' ]]; then @@ -1525,14 +1569,16 @@ function change_zshrc() { { print -n >$tmp || return - if (( !zshrc_has_pre )); then - >>$tmp print -r -- "# Enable Powerlevel10k instant prompt. Should stay at the top of ${(%)__p9k_zshrc_u}. + if (( !zshrc_has_instant_prompt )); then + >>$tmp print -r -- "# Enable Powerlevel10k instant prompt. Should stay close to the top of ${(%)__p9k_zshrc_u}. +# Initialization code that may require console input (password prompts, [y/n] +# confirmations, etc.) must go above this block, everything else must go below. if [[ -r \"\${XDG_CACHE_HOME:-\$HOME/.cache}/p10k-instant-prompt-\${(%):-%n}.zsh\" ]]; then source \"\${XDG_CACHE_HOME:-\$HOME/.cache}/p10k-instant-prompt-\${(%):-%n}.zsh\" fi" || return fi if [[ -n $zshrc_content ]]; then - (( zshrc_has_pre )) || print >>$tmp || return + (( zshrc_has_instant_prompt )) || print >>$tmp || return >>$tmp print -r -- $zshrc_content || return fi if (( !zshrc_has_cfg )); then @@ -1540,11 +1586,6 @@ fi" || return # To customize prompt, run \`p10k configure\` or edit ${(%)__p9k_cfg_path_u}. [[ ! -f ${(%)__p9k_cfg_path_u} ]] || source ${(%)__p9k_cfg_path_u}" || return fi - if (( !zshrc_has_post )); then - >>$tmp print -r -- " -# Finalize Powerlevel10k instant prompt. Should stay at the bottom of ${(%)__p9k_zshrc_u}. -(( ! \${+functions[p10k-instant-prompt-finalize]} )) || p10k-instant-prompt-finalize" || return - fi zf_mv -f -- $tmp $__p9k_zshrc || return } always { zf_rm -f -- $tmp @@ -1568,8 +1609,8 @@ fi source $__p9k_root_dir/internal/icons.zsh || return while true; do - local zshrc_content= zshrc_backup= zshrc_backup_u= - local -i zshrc_has_cfg=0 zshrc_has_pre=0 zshrc_has_post=0 write_zshrc=0 + 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=' ' local left_subsep= right_subsep= left_tail= right_tail= left_head= right_head= show_time= local -i num_lines=0 empty_line=0 color=2 left_frame=1 right_frame=1 @@ -1649,6 +1690,7 @@ while true; do ask_prefixes || continue fi ask_confirm || continue + ask_instant_prompt || continue ask_config_overwrite || continue ask_zshrc_edit || continue break |