mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2025-12-04 21:56:46 +01:00
improve instant prompt usability, update docs and add an option to the wizard to enable it
This commit is contained in:
parent
f17081ca98
commit
627d471fca
8 changed files with 312 additions and 108 deletions
|
|
@ -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,25 +1569,22 @@ 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
|
||||
>>$tmp print -r -- "
|
||||
# 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 {
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue