enable instant prompt when configuration wizard runs

pull/275/head
romkatv 5 years ago
parent 32f363a1b1
commit 4f02ad912f

@ -87,7 +87,7 @@ Add `antibody bundle romkatv/powerlevel10k` to your `~/.zshrc`.
Add `zplugin ice depth=1; zplugin light romkatv/powerlevel10k` to your `~/.zshrc`. Add `zplugin ice depth=1; zplugin light romkatv/powerlevel10k` to your `~/.zshrc`.
The use of `depth` ice is optional. Other types of ice are neither recommended nor officially The use of `depth=1` ice is optional. Other types of ice are neither recommended nor officially
supported by Powerlevel10k. supported by Powerlevel10k.
## Configuration ## Configuration

@ -812,6 +812,9 @@
# User-defined prompt segments can be customized the same way as built-in segments. # User-defined prompt segments can be customized the same way as built-in segments.
typeset -g POWERLEVEL9K_EXAMPLE_FOREGROUND=208 typeset -g POWERLEVEL9K_EXAMPLE_FOREGROUND=208
typeset -g POWERLEVEL9K_EXAMPLE_VISUAL_IDENTIFIER_EXPANSION='${P9K_VISUAL_IDENTIFIER}' typeset -g POWERLEVEL9K_EXAMPLE_VISUAL_IDENTIFIER_EXPANSION='${P9K_VISUAL_IDENTIFIER}'
# When instant prompt is disabled, prompt won't appear until zsh is fully initialized.
# typeset -g POWERLEVEL9K_DISABLE_INSTANT_PROMPT=true
} }
(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]} (( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]}

@ -792,6 +792,9 @@
# User-defined prompt segments can be customized the same way as built-in segments. # User-defined prompt segments can be customized the same way as built-in segments.
typeset -g POWERLEVEL9K_EXAMPLE_FOREGROUND=208 typeset -g POWERLEVEL9K_EXAMPLE_FOREGROUND=208
typeset -g POWERLEVEL9K_EXAMPLE_VISUAL_IDENTIFIER_EXPANSION='${P9K_VISUAL_IDENTIFIER}' typeset -g POWERLEVEL9K_EXAMPLE_VISUAL_IDENTIFIER_EXPANSION='${P9K_VISUAL_IDENTIFIER}'
# When instant prompt is disabled, prompt won't appear until zsh is fully initialized.
# typeset -g POWERLEVEL9K_DISABLE_INSTANT_PROMPT=true
} }
(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]} (( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]}

@ -838,6 +838,9 @@
# User-defined prompt segments can be customized the same way as built-in segments. # User-defined prompt segments can be customized the same way as built-in segments.
# typeset -g POWERLEVEL9K_EXAMPLE_FOREGROUND=4 # typeset -g POWERLEVEL9K_EXAMPLE_FOREGROUND=4
typeset -g POWERLEVEL9K_EXAMPLE_VISUAL_IDENTIFIER_EXPANSION='${P9K_VISUAL_IDENTIFIER}' typeset -g POWERLEVEL9K_EXAMPLE_VISUAL_IDENTIFIER_EXPANSION='${P9K_VISUAL_IDENTIFIER}'
# When instant prompt is disabled, prompt won't appear until zsh is fully initialized.
# typeset -g POWERLEVEL9K_DISABLE_INSTANT_PROMPT=true
} }
(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]} (( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]}

@ -10,6 +10,8 @@ if [[ ${langinfo[CODESET]:-} != (utf|UTF)(-|)8 ]]; then
local LC_ALL=${${(@M)$(locale -a):#*.(utf|UTF)(-|)8}[1]:-en_US.UTF-8} local LC_ALL=${${(@M)$(locale -a):#*.(utf|UTF)(-|)8}[1]:-en_US.UTF-8}
fi fi
zmodload -F zsh/files b:zf_mv b:zf_rm
typeset -g __p9k_root_dir typeset -g __p9k_root_dir
typeset -gi force=0 typeset -gi force=0
@ -1238,8 +1240,8 @@ function ask_confirm() {
function ask_config_overwrite() { function ask_config_overwrite() {
config_backup= config_backup=
config_backup_u=0
if [[ ! -e $__p9k_cfg_path ]]; then if [[ ! -e $__p9k_cfg_path ]]; then
write_config=1
return return
fi fi
while true; do while true; do
@ -1262,13 +1264,75 @@ function ask_config_overwrite() {
config_backup="$(mktemp ${TMPDIR:-/tmp}/$__p9k_cfg_basename.XXXXXXXXXX)" || exit 1 config_backup="$(mktemp ${TMPDIR:-/tmp}/$__p9k_cfg_basename.XXXXXXXXXX)" || exit 1
cp $__p9k_cfg_path $config_backup || exit 1 cp $__p9k_cfg_path $config_backup || exit 1
config_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)config_backup:t} config_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)config_backup:t}
write_config=1
break break
;; ;;
esac esac
done done
} }
function ask_zshrc_edit() {
zshrc_content=
zshrc_backup=
zshrc_backup_u=
zshrc_has_cfg=0
zshrc_has_pre=0
zshrc_has_post=0
write_zshrc=0
if [[ -e $__p9k_zshrc ]]; then
zshrc_content="$(<$__p9k_zshrc)" || quit -c
local lines=(${(f)zshrc_content})
local f0=$__p9k_cfg_path
local f1=${(q)f0}
local f2=${(q-)f0}
local f3=${(qq)f0}
local f4=${(qqq)f0}
local g1=${${(q)__p9k_cfg_path}/#(#b)${(q)HOME}\//'~/'}
if [[ -n ${(@M)lines:#(#b)[^#]#([^[:IDENT:]]|)source[[:space:]]##($f1|$f2|$f3|$f4|$g1)(|[[:space:]]*|'#'*)} ]]; then
zshrc_has_cfg=1
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
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
fi
while true; do
clear
flowing -c "%BApply changes to %b%2F${__p9k_zshrc_u//\\/\\\\}%f%B?%b"
print -P ""
print -P "%B(y) Yes (recommended).%b"
print -P ""
print -P "%B(n) No. I know which changes to apply and will do it myself.%b"
print -P ""
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
case $key in
q) quit;;
r) return 1;;
n) return 0;;
y)
write_zshrc=1
if [[ -n $zshrc_content ]]; then
zshrc_backup="$(mktemp ${TMPDIR:-/tmp}/.zshrc.XXXXXXXXXX)" || quit -c
cp -p $__p9k_zshrc $zshrc_backup || quit -c
print -r -- $zshrc_content >$zshrc_backup || quit -c
zshrc_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)zshrc_backup:t}
break
fi
;;
esac
done
}
function generate_config() { function generate_config() {
if [[ $style == pure ]]; then if [[ $style == pure ]]; then
if [[ -e $__p9k_cfg_path ]]; then if [[ -e $__p9k_cfg_path ]]; then
@ -1447,35 +1511,52 @@ function generate_config() {
header+=$'.\n# Type `p10k configure` to generate another config.\n#' header+=$'.\n# Type `p10k configure` to generate another config.\n#'
if [[ -e $__p9k_cfg_path ]]; then if [[ -e $__p9k_cfg_path ]]; then
unlink $__p9k_cfg_path || return 1 unlink $__p9k_cfg_path || return
fi fi
print -lr -- "$header" "$lines[@]" >$__p9k_cfg_path print -lr -- "$header" "$lines[@]" >$__p9k_cfg_path
} }
function write_zshrc() { function change_zshrc() {
if [[ -e $__p9k_zshrc ]]; then (( write_zshrc )) || return 0
local lines=(${(f)"$(<$__p9k_zshrc)"})
local f0=$__p9k_cfg_path local tmp=$__p9k_zshrc.${(%):-%n}.tmp.$$
local f1=${(q)f0} [[ ! -e $__p9k_zshrc ]] || cp -p $__p9k_zshrc $tmp || return
local f2=${(q-)f0}
local f3=${(qq)f0} {
local f4=${(qqq)f0} print -n >$tmp || return
local g1=${${(q)__p9k_cfg_path}/#(#b)${(q)HOME}\//'~/'}
if [[ -n ${(@M)lines:#(#b)[^#]#([^[:IDENT:]]|)source[[:space:]]##($f1|$f2|$f3|$f4|$g1)(|[[:space:]]*|'#'*)} ]]; then
flowing +c No changes have been made to %4F$__p9k_zshrc_u%f because it already sources %2F$__p9k_cfg_path_u%f.
return
fi
fi
local comments=( if (( !zshrc_has_pre )); then
"# To customize prompt, run \`p10k configure\` or edit $__p9k_cfg_path_u." >>$tmp print -r -- "# Enable Powerlevel10k instant prompt. Should stay at the top of ${(%)__p9k_zshrc_u}.
) if [[ -r \"\${XDG_CACHE_HOME:-\$HOME/.cache}/p10k-instant-prompt-\${(%):-%n}.zsh\" ]]; then
print -lrP -- "" $comments "[[ -f $__p9k_cfg_path_u ]] && source $__p9k_cfg_path_u" >>$__p9k_zshrc 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
>>$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 {
zf_rm -f -- $tmp
}
print -rP "" if [[ -n $zshrc_backup_u ]]; then
flowing +c The following lines have been appended to %4F$__p9k_zshrc_u%f: print -rP ""
print -rP "" flowing +c See "%B${__p9k_zshrc_u//\\/\\\\}%b" changes:
print -lrP -- ' '${^comments} " %3F[[%f %B-f $__p9k_cfg_path_u%b %3F]]%f && %2Fsource%f %B$__p9k_cfg_path_u%b" print -rP "
%2Fdiff%f %B$zshrc_backup_u%b %B$__p9k_zshrc_u%b"
fi
return 0
} }
if (( force )); then if (( force )); then
@ -1487,9 +1568,11 @@ fi
source $__p9k_root_dir/internal/icons.zsh || return source $__p9k_root_dir/internal/icons.zsh || return
while true; do 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 POWERLEVEL9K_MODE= style= config_backup= config_backup_u= gap_char=' ' 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 left_subsep= right_subsep= left_tail= right_tail= left_head= right_head= show_time=
local -i num_lines=0 write_config=0 empty_line=0 color=2 left_frame=1 right_frame=1 local -i num_lines=0 empty_line=0 color=2 left_frame=1 right_frame=1
local -i cap_diamond=0 cap_python=0 cap_debian=0 cap_narrow_icons=0 cap_lock=0 local -i cap_diamond=0 cap_python=0 cap_debian=0 cap_narrow_icons=0 cap_lock=0
local -a extra_icons=('' '' '') local -a extra_icons=('' '' '')
local -a prefixes=('' '') local -a prefixes=('' '')
@ -1567,21 +1650,22 @@ while true; do
fi fi
ask_confirm || continue ask_confirm || continue
ask_config_overwrite || continue ask_config_overwrite || continue
ask_zshrc_edit || continue
break break
done done
clear clear
flowing +c Powerlevel10k configuration has been written to %2F$__p9k_cfg_path_u%f. flowing +c New config: "%B${__p9k_cfg_path_u//\\/\\\\}%b."
if [[ -n $config_backup ]]; then if [[ -n $config_backup ]]; then
flowing +c The backup of the previous version is at %3F$config_backup_u%f. flowing +c Backup of the old config: "%B${config_backup_u//\\/\\\\}%b."
fi fi
if [[ -n $zshrc_backup ]]; then
if (( write_config )); then flowing +c Backup of "%B${__p9k_zshrc_u//\\/\\\\}%b:" "%B${zshrc_backup_u//\\/\\\\}%b."
generate_config || return
fi fi
write_zshrc || return generate_config || return
change_zshrc || return
print -rP "" print -rP ""
flowing +c File feature requests and bug reports at "$(href https://github.com/romkatv/powerlevel10k/issues)." flowing +c File feature requests and bug reports at "$(href https://github.com/romkatv/powerlevel10k/issues)."

Loading…
Cancel
Save