wizard: encode generation source and options

pull/145/head
romkatv 5 years ago
parent ef57656e88
commit 1731b69f5f

@ -180,19 +180,19 @@ function _p9k_ask_style() {
_p9k_clear _p9k_clear
print -P " %BChoose your prompt style%b" print -P " %BChoose your prompt style%b"
print -P "" print -P ""
print -P " %B%3FLean%f%b" print -P " %BLean%b"
print -P "" print -P ""
print -P " %B%39F~%b%12F/%B%39Fpowerlevel10k%b %76Fmaster ⇡2%f" print -P " %B%39F~%b%12F/%B%39Fpowerlevel10k%b %76Fmaster ⇡2%f"
print -P " %76F%f █" print -P " %76F%f █"
print -P "" print -P ""
print -P " %B%3FClassic%f%b" print -P " %BClassic%b"
print -P "" print -P ""
print -P " %8F╭─%K{0} %B%39F~%b%K{0}%12F/%B%39Fpowerlevel10k%b%K{0} %244F\uE0B1 %76Fmaster ⇡2 %k%0F\uE0B0" print -P " %8F╭─%K{0} %B%39F~%b%K{0}%12F/%B%39Fpowerlevel10k%b%K{0} %244F\uE0B1 %76Fmaster ⇡2 %k%0F\uE0B0"
print -P " %8F╰─%f █" print -P " %8F╰─%f █"
print -P "" print -P ""
print -P "(%B1%b) %B%3FLean%f%b." print -P "(%B1%b) Lean."
print -P "" print -P ""
print -P "(%B2%b) %B%4FClassic%f%b." print -P "(%B2%b) Classic."
print -P "" print -P ""
print -P "%248F(r) Restart from the beginning.%f" print -P "%248F(r) Restart from the beginning.%f"
print -P "" print -P ""
@ -223,7 +223,7 @@ function _p9k_ask_lines() {
print -P " %K{0} %B%39F~%b%K{0}%12F/%B%39Fpowerlevel10k%b%K{0} %244F\uE0B1 %76Fmaster ⇡2 %k%0F\uE0B0%f █" print -P " %K{0} %B%39F~%b%K{0}%12F/%B%39Fpowerlevel10k%b%K{0} %244F\uE0B1 %76Fmaster ⇡2 %k%0F\uE0B0%f █"
fi fi
print -P "" print -P ""
print -P " %BTwo Lines%b" print -P " %BTwo Lines%b"
print -P "" print -P ""
if [[ $_p9k_style == lean ]]; then if [[ $_p9k_style == lean ]]; then
print -P " %B%39F~%b%12F/%B%39Fpowerlevel10k%b %76Fmaster ⇡2%f" print -P " %B%39F~%b%12F/%B%39Fpowerlevel10k%b %76Fmaster ⇡2%f"
@ -288,8 +288,9 @@ function _p9k_ask_overwrite() {
} }
function _p9k_generate_config() { function _p9k_generate_config() {
local -a cfg && cfg=("${(@f)$(< $_p9k_root_dir/config/p10k-$_p9k_style.zsh)}") || return local base && base="$(< $_p9k_root_dir/config/p10k-$_p9k_style.zsh)" || return
cfg=("${(@)cfg/# typeset -g POWERLEVEL9K_MODE=*/ typeset -g POWERLEVEL9K_MODE=$POWERLEVEL9K_MODE}") local lines=("${(@f)base}")
lines=("${(@)lines/# typeset -g POWERLEVEL9K_MODE=*/ typeset -g POWERLEVEL9K_MODE=$POWERLEVEL9K_MODE}")
if [[ $POWERLEVEL9K_MODE == (powerline|compatible) && $_p9k_style == lean ]]; then if [[ $POWERLEVEL9K_MODE == (powerline|compatible) && $_p9k_style == lean ]]; then
local exp="''" local exp="''"
elif (( _p9k_caps_narrow_icons )); then elif (( _p9k_caps_narrow_icons )); then
@ -297,16 +298,26 @@ function _p9k_generate_config() {
else else
local exp="'\${P9K_VISUAL_IDENTIFIER}'" local exp="'\${P9K_VISUAL_IDENTIFIER}'"
fi fi
cfg=("${(@)cfg/# typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION=*/ typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION=$exp}") lines=("${(@)lines/# typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION=*/ typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION=$exp}")
if (( _p9k_lines == 1 )); then if (( _p9k_lines == 1 )); then
local -a tmp local -a tmp
local line local line
for line in "$cfg[@]"; do for line in "$lines[@]"; do
[[ $line == (' newline'|*'===[ Line #'*) ]] || tmp+=$line [[ $line == (' newline'|*'===[ Line #'*) ]] || tmp+=$line
done done
cfg=("$tmp[@]") lines=("$tmp[@]")
fi fi
print -lr -- "$cfg[@]" >$zd/.p10k.zsh local header=${(%):-"# Generated by Powerlevel10k configuration wizard on %D{%Y-%m-%d at %H:%M %Z}."}$'\n'
header+="# Based on romkatv/powerlevel10k/config/p10k-$_p9k_style.zsh"
if [[ $commands[sum] == ('/bin'|'/usr/bin'|'/usr/local/bin')'/sum' ]]; then
local -a sum
if sum=($(sum <<<${base//$'\r\n'/$'\n'} 2>/dev/null)) && (( $#sum == 2 )); then
header+=", checksum $sum[1]"
fi
fi
header+=$'.\n'
header+="# Wizard options: font=$POWERLEVEL9K_MODE, lines=$_p9k_lines, narrow-icons=$_p9k_caps_narrow_icons."$'\n#'
print -lr -- "$header" "$lines[@]" >$zd/.p10k.zsh
} }
function _p9k_configure() { function _p9k_configure() {

Loading…
Cancel
Save