mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-12 08:10:07 +00:00
add -f and straight
This commit is contained in:
parent
84694f3ef2
commit
c87396abcb
1 changed files with 101 additions and 29 deletions
|
@ -4,7 +4,27 @@ emulate -L zsh
|
||||||
setopt extended_glob noaliases
|
setopt extended_glob noaliases
|
||||||
|
|
||||||
() {
|
() {
|
||||||
typeset -gr __p9k_root_dir=${1:-${0:h:h:A}}
|
|
||||||
|
typeset -g __p9k_root_dir
|
||||||
|
typeset -gi force=0
|
||||||
|
|
||||||
|
local opt
|
||||||
|
while getopts 'd:f' opt; do
|
||||||
|
case $opt in
|
||||||
|
d) __p9k_root_dir=$OPTARG;;
|
||||||
|
f) force=1;;
|
||||||
|
+f) force=0;;
|
||||||
|
'?') return 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if (( OPTIND <= ARGC )); then
|
||||||
|
print -lr -- "wizard.zsh: invalid arguments: $@" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
: ${__p9k_root_dir:=${0:h:h:A}}
|
||||||
|
|
||||||
source $__p9k_root_dir/internal/configure.zsh || return
|
source $__p9k_root_dir/internal/configure.zsh || return
|
||||||
|
|
||||||
typeset -ra lean_left=(
|
typeset -ra lean_left=(
|
||||||
|
@ -30,7 +50,7 @@ typeset -ra classic_right=(
|
||||||
typeset -ri prompt_indent=4
|
typeset -ri prompt_indent=4
|
||||||
|
|
||||||
local POWERLEVEL9K_MODE style config_backup gap_char
|
local POWERLEVEL9K_MODE style config_backup gap_char
|
||||||
local -i num_lines write_config flat_sep empty_line
|
local -i num_lines write_config straight empty_line
|
||||||
local -i cap_diamond cap_python cap_narrow_icons cap_lock
|
local -i cap_diamond cap_python cap_narrow_icons cap_lock
|
||||||
|
|
||||||
function prompt_length() {
|
function prompt_length() {
|
||||||
|
@ -59,9 +79,10 @@ function print_prompt() {
|
||||||
left=($left[2] $left[4])
|
left=($left[2] $left[4])
|
||||||
right=($right[1] $right[3])
|
right=($right[1] $right[3])
|
||||||
fi
|
fi
|
||||||
if (( flat_sep )); then
|
if (( straight )); then
|
||||||
left=("${(@)${(@)left//\\uE0B1/|}//\\uE0B0/▓▒░}")
|
(( cap_diamond )) && local subsep='\uE0BD' || local subsep='|'
|
||||||
right=("${(@)${(@)right//\\uE0B3/|}//\\uE0B2/░▒▓}")
|
left=("${(@)${(@)left//\\uE0B1/$subsep}//\\uE0B0/▓▒░}")
|
||||||
|
right=("${(@)${(@)right//\\uE0B3/$subsep}//\\uE0B2/░▒▓}")
|
||||||
fi
|
fi
|
||||||
local -i i
|
local -i i
|
||||||
for ((i = 1; i < $#left; i+=2)); do
|
for ((i = 1; i < $#left; i+=2)); do
|
||||||
|
@ -98,6 +119,11 @@ function clear() {
|
||||||
|
|
||||||
function quit() {
|
function quit() {
|
||||||
clear
|
clear
|
||||||
|
if (( force )); then
|
||||||
|
print -P "Powerlevel10k configuration wizard has been aborted. To run it again, type:"
|
||||||
|
print -P ""
|
||||||
|
print -P " %2Fp9k_configure%f"
|
||||||
|
else
|
||||||
print -P "Powerlevel10k configuration wizard will run again next time unless"
|
print -P "Powerlevel10k configuration wizard will run again next time unless"
|
||||||
print -P "you define at least one Powerlevel10k configuration option. To define"
|
print -P "you define at least one Powerlevel10k configuration option. To define"
|
||||||
print -P "an option that does nothing except for disabling Powerlevel10k"
|
print -P "an option that does nothing except for disabling Powerlevel10k"
|
||||||
|
@ -105,14 +131,23 @@ function quit() {
|
||||||
print -P ""
|
print -P ""
|
||||||
print -P " %2Fecho%f %3F'POWERLEVEL9K_MODE='%f %15F>>! $__p9k_zshrc_u%f"
|
print -P " %2Fecho%f %3F'POWERLEVEL9K_MODE='%f %15F>>! $__p9k_zshrc_u%f"
|
||||||
print -P ""
|
print -P ""
|
||||||
|
print -P "To run Powerlevel10k configuration wizard right now, type:"
|
||||||
|
print -P ""
|
||||||
|
print -P " %2Fp9k_configure%f"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function ask_diamond() {
|
function ask_diamond() {
|
||||||
while true; do
|
while true; do
|
||||||
clear
|
clear
|
||||||
|
if (( force )); then
|
||||||
|
print -P "This is %B%4FPowerlevel10k configuration wizard%f%b. It will ask you a few"
|
||||||
|
print -P "questions and configure your prompt."
|
||||||
|
else
|
||||||
print -P "This is %B%4FPowerlevel10k configuration wizard%f%b. You are seeing it because"
|
print -P "This is %B%4FPowerlevel10k configuration wizard%f%b. You are seeing it because"
|
||||||
print -P "you haven't defined any Powerlevel10k configuration options. It will"
|
print -P "you haven't defined any Powerlevel10k configuration options. It will"
|
||||||
print -P "ask you a few questions and configure your prompt."
|
print -P "ask you a few questions and configure your prompt."
|
||||||
|
fi
|
||||||
print -P ""
|
print -P ""
|
||||||
centered "%BDoes this look like a %2Fdiamond%f (square rotated 45 degrees)?%b"
|
centered "%BDoes this look like a %2Fdiamond%f (square rotated 45 degrees)?%b"
|
||||||
centered "reference: $(href https://graphemica.com/%E2%97%86)"
|
centered "reference: $(href https://graphemica.com/%E2%97%86)"
|
||||||
|
@ -260,9 +295,9 @@ function ask_style() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function ask_flat_sep() {
|
function ask_straight() {
|
||||||
if [[ $style != classic || $cap_diamond == 0 ]]; then
|
if [[ $style != classic || $cap_diamond == 0 ]]; then
|
||||||
flat_sep=1
|
straight=1
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
while true; do
|
while true; do
|
||||||
|
@ -271,11 +306,11 @@ function ask_flat_sep() {
|
||||||
print -P ""
|
print -P ""
|
||||||
print -P "%B(1) Angled%b"
|
print -P "%B(1) Angled%b"
|
||||||
print -P ""
|
print -P ""
|
||||||
flat_sep=0 print_prompt
|
straight=0 print_prompt
|
||||||
print -P ""
|
print -P ""
|
||||||
print -P "%B(2) Flat%b"
|
print -P "%B(2) Straight%b"
|
||||||
print -P ""
|
print -P ""
|
||||||
flat_sep=1 print_prompt
|
straight=1 print_prompt
|
||||||
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 ""
|
||||||
|
@ -287,8 +322,8 @@ function ask_flat_sep() {
|
||||||
case $key in
|
case $key in
|
||||||
q) quit; return 1;;
|
q) quit; return 1;;
|
||||||
r) return 2;;
|
r) return 2;;
|
||||||
1) flat_sep=0; break;;
|
1) straight=0; break;;
|
||||||
2) flat_sep=1; break;;
|
2) straight=1; break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -456,14 +491,32 @@ function generate_config() {
|
||||||
function sub() {
|
function sub() {
|
||||||
lines=("${(@)lines/# typeset -g POWERLEVEL9K_$1=*/ typeset -g POWERLEVEL9K_$1=$2}")
|
lines=("${(@)lines/# typeset -g POWERLEVEL9K_$1=*/ typeset -g POWERLEVEL9K_$1=$2}")
|
||||||
}
|
}
|
||||||
|
|
||||||
sub MODE $POWERLEVEL9K_MODE
|
sub MODE $POWERLEVEL9K_MODE
|
||||||
if [[ $POWERLEVEL9K_MODE == (powerline|compatible) && $style == lean ]]; then
|
|
||||||
sub VISUAL_IDENTIFIER_EXPANSION "''"
|
if (( cap_narrow_icons )); then
|
||||||
elif (( cap_narrow_icons )); then
|
|
||||||
sub VISUAL_IDENTIFIER_EXPANSION "'\${P9K_VISUAL_IDENTIFIER// }'"
|
sub VISUAL_IDENTIFIER_EXPANSION "'\${P9K_VISUAL_IDENTIFIER// }'"
|
||||||
|
sub BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION "'\${P9K_VISUAL_IDENTIFIER// }'"
|
||||||
else
|
else
|
||||||
sub VISUAL_IDENTIFIER_EXPANSION "'\${P9K_VISUAL_IDENTIFIER}'"
|
sub VISUAL_IDENTIFIER_EXPANSION "'\${P9K_VISUAL_IDENTIFIER}'"
|
||||||
|
sub BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION "'\${P9K_VISUAL_IDENTIFIER}'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $POWERLEVEL9K_MODE == compatible ]]; then
|
||||||
|
# Many fonts don't have the gear icon.
|
||||||
|
sub BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION "'⇶'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( straight )); then
|
||||||
|
(( cap_diamond )) && local subsep='\uE0BD' || local subsep='|'
|
||||||
|
sub LEFT_SUBSEGMENT_SEPARATOR "'%244F$subsep'"
|
||||||
|
sub RIGHT_SUBSEGMENT_SEPARATOR "'%244F$subsep'"
|
||||||
|
sub LEFT_SEGMENT_SEPARATOR "'$subsep'"
|
||||||
|
sub RIGHT_SEGMENT_SEPARATOR "'$subsep'"
|
||||||
|
sub LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL "'▓▒░'"
|
||||||
|
sub RIGHT_PROMPT_FIRST_SEGMENT_START_SYMBOL "'░▒▓'"
|
||||||
|
fi
|
||||||
|
|
||||||
if (( num_lines == 1 )); then
|
if (( num_lines == 1 )); then
|
||||||
local -a tmp
|
local -a tmp
|
||||||
local line
|
local line
|
||||||
|
@ -472,6 +525,11 @@ function generate_config() {
|
||||||
done
|
done
|
||||||
lines=("$tmp[@]")
|
lines=("$tmp[@]")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
sub MULTILINE_FIRST_PROMPT_GAP_CHAR "'$gap_char'"
|
||||||
|
|
||||||
|
(( empty_line )) && sub PROMPT_ADD_NEWLINE true || sub PROMPT_ADD_NEWLINE false
|
||||||
|
|
||||||
local header=${(%):-"# Generated by Powerlevel10k configuration wizard on %D{%Y-%m-%d at %H:%M %Z}."}$'\n'
|
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"
|
header+="# Based on romkatv/powerlevel10k/config/p10k-$style.zsh"
|
||||||
if [[ $commands[sum] == ('/bin'|'/usr/bin'|'/usr/local/bin')'/sum' ]]; then
|
if [[ $commands[sum] == ('/bin'|'/usr/bin'|'/usr/local/bin')'/sum' ]]; then
|
||||||
|
@ -481,7 +539,21 @@ function generate_config() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
header+=$'.\n'
|
header+=$'.\n'
|
||||||
header+="# Wizard options: font=$POWERLEVEL9K_MODE, lines=$num_lines, narrow-icons=$cap_narrow_icons."$'\n#'
|
header+="# Wizard options: $POWERLEVEL9K_MODE font"
|
||||||
|
(( cap_narrow_icons )) && header+=", narrow icons" || header+=", wide icons"
|
||||||
|
header+=", $style"
|
||||||
|
if [[ $style == classic ]]; then
|
||||||
|
(( straight )) && header+=", straight" || header+=", angled"
|
||||||
|
fi
|
||||||
|
(( num_lines == 1 )) && header+=", 1 line" || header+=", $num_lines lines"
|
||||||
|
case $gap_char in
|
||||||
|
' ') header+=", disconnected";;
|
||||||
|
'·') header+=", dotted";;
|
||||||
|
'─') header+=", solid";;
|
||||||
|
esac
|
||||||
|
(( empty_line )) && header+=", sparse" || header+=", compact";
|
||||||
|
header+=$'.\n#'
|
||||||
|
|
||||||
if [[ -e $__p9k_cfg_path ]]; then
|
if [[ -e $__p9k_cfg_path ]]; then
|
||||||
unlink $__p9k_cfg_path || return 1
|
unlink $__p9k_cfg_path || return 1
|
||||||
fi
|
fi
|
||||||
|
@ -506,7 +578,7 @@ function write_zshrc() {
|
||||||
|
|
||||||
local comments=(
|
local comments=(
|
||||||
"# You can customize your prompt by editing $__p9k_cfg_path_u."
|
"# You can customize your prompt by editing $__p9k_cfg_path_u."
|
||||||
"# To run configuration wizard again, remove the next line."
|
"# To run Powerlevel10k configuration wizard, type 'p9k_configure."
|
||||||
)
|
)
|
||||||
print -lr -- "" $comments "source $__p9k_cfg_path_u" >>$__p9k_zshrc
|
print -lr -- "" $comments "source $__p9k_cfg_path_u" >>$__p9k_zshrc
|
||||||
|
|
||||||
|
@ -521,7 +593,7 @@ source $__p9k_root_dir/internal/icons.zsh || return
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
ask_diamond || { (( $? == 2 )) && continue || return }
|
ask_diamond || { (( $? == 2 )) && continue || return }
|
||||||
(( cap_diamond )) || flat_sep=1
|
(( cap_diamond )) || straight=1
|
||||||
if [[ -n $AWESOME_GLYPHS_LOADED ]]; then
|
if [[ -n $AWESOME_GLYPHS_LOADED ]]; then
|
||||||
POWERLEVEL9K_MODE=awesome-mapped-fontconfig
|
POWERLEVEL9K_MODE=awesome-mapped-fontconfig
|
||||||
else
|
else
|
||||||
|
@ -541,7 +613,7 @@ while true; do
|
||||||
_p9k_init_icons
|
_p9k_init_icons
|
||||||
ask_narrow_icons || { (( $? == 2 )) && continue || return }
|
ask_narrow_icons || { (( $? == 2 )) && continue || return }
|
||||||
ask_style || { (( $? == 2 )) && continue || return }
|
ask_style || { (( $? == 2 )) && continue || return }
|
||||||
ask_flat_sep || { (( $? == 2 )) && continue || return }
|
ask_straight || { (( $? == 2 )) && continue || return }
|
||||||
ask_num_lines || { (( $? == 2 )) && continue || return }
|
ask_num_lines || { (( $? == 2 )) && continue || return }
|
||||||
ask_gap_char || { (( $? == 2 )) && continue || return }
|
ask_gap_char || { (( $? == 2 )) && continue || return }
|
||||||
ask_empty_line || { (( $? == 2 )) && continue || return }
|
ask_empty_line || { (( $? == 2 )) && continue || return }
|
||||||
|
|
Loading…
Reference in a new issue