my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2153 lines
67 KiB

3 years ago
  1. local -i force=0
  2. local opt
  3. while getopts 'f' opt; do
  4. case $opt in
  5. f) force=1;;
  6. +f) force=0;;
  7. \?) return 1;;
  8. esac
  9. done
  10. if (( OPTIND <= ARGC )); then
  11. print -lr -- "wizard.zsh: invalid arguments: $@" >&2
  12. return 1
  13. fi
  14. local -i in_z4h_wizard=0
  15. [[ $force == 0 && $+functions[z4h] == 1 && -n $Z4H && -e $Z4H/welcome ]] && in_z4h_wizard=1
  16. local -i success=0
  17. local -ri force
  18. local -r font_base_url='https://github.com/romkatv/powerlevel10k-media/raw/master'
  19. local -ri prompt_indent=2
  20. local -rA pure_original=(grey 242 red 1 yellow 3 blue 4 magenta 5 cyan 6 white 7)
  21. local -rA pure_snazzy=(grey 242 red '#FF5C57' yellow '#F3F99D' blue '#57C7FF' magenta '#FF6AC1' cyan '#9AEDFE' white '#F1F1F0')
  22. local -ra bg_color=(240 238 236 234)
  23. local -ra sep_color=(248 246 244 242)
  24. local -ra prefix_color=(250 248 246 244)
  25. local -r left_circle='\uE0B6'
  26. local -r right_circle='\uE0B4'
  27. local -r left_arc='\uE0B7'
  28. local -r right_arc='\uE0B5'
  29. local -r left_triangle='\uE0B2'
  30. local -r right_triangle='\uE0B0'
  31. local -r left_angle='\uE0B3'
  32. local -r right_angle='\uE0B1'
  33. local -r fade_in='░▒▓'
  34. local -r fade_out='▓▒░'
  35. local -r vertical_bar='\u2502'
  36. local -r cursor='%1{\e[07m \e[27m%}'
  37. local -r time_24h='16:23:42'
  38. local -r time_12h='04:23:42 PM'
  39. local -ra lean_left=(
  40. '%$frame_color[$color]F╭─ ' '${extra_icons[1]:+%f$extra_icons[1] }%31F$extra_icons[2]%B%39F~%b%31F/%B%39Fsrc%b%f $prefixes[1]%76F$extra_icons[3]master%f '
  41. '%$frame_color[$color]F╰─' '%76F$prompt_char%f ${buffer:-$cursor}'
  42. )
  43. local -ra lean_right=(
  44. ' $prefixes[2]%101F$extra_icons[4]5s%f${time:+ $prefixes[3]%66F$extra_icons[5]$time%f}' ' %$frame_color[$color]F─╮%f'
  45. '' ' %$frame_color[$color]F─╯%f'
  46. )
  47. local -ra lean_8colors_left=(
  48. '%$frame_color[$color]F╭─ ' '${extra_icons[1]:+%f$extra_icons[1] }%4F$extra_icons[2]%4F~/src%f $prefixes[1]%2F$extra_icons[3]master%f '
  49. '%$frame_color[$color]F╰─' '%2F$prompt_char%f ${buffer:-$cursor}'
  50. )
  51. local -ra lean_8colors_right=(
  52. ' $prefixes[2]%3F$extra_icons[4]5s%f${time:+ $prefixes[3]%6F$extra_icons[5]$time%f}' ' %$frame_color[$color]F─╮%f'
  53. '' ' %$frame_color[$color]F─╯%f'
  54. )
  55. local -ra classic_left=(
  56. '%$frame_color[$color]F╭─' '%F{$bg_color[$color]}$left_tail%K{$bg_color[$color]} ${extra_icons[1]:+%255F$extra_icons[1] %$sep_color[$color]F$left_subsep%f }%31F$extra_icons[2]%B%39F~%b%K{$bg_color[$color]}%31F/%B%39Fsrc%b%K{$bg_color[$color]} %$sep_color[$color]F$left_subsep%f %$prefix_color[$color]F$prefixes[1]%76F$extra_icons[3]master %k%$bg_color[$color]F$left_head%f'
  57. '%$frame_color[$color]F╰─' '%f ${buffer:-$cursor}'
  58. )
  59. local -ra classic_right=(
  60. '%$bg_color[$color]F$right_head%K{$bg_color[$color]}%f %$prefix_color[$color]F$prefixes[2]%101F5s $extra_icons[4]${time:+%$sep_color[$color]F$right_subsep %$prefix_color[$color]F$prefixes[3]%66F$time $extra_icons[5]}%k%F{$bg_color[$color]}$right_tail%f' '%$frame_color[$color]F─╮%f'
  61. '' '%$frame_color[$color]F─╯%f'
  62. )
  63. local -ra pure_left=(
  64. '' '%F{$pure_color[blue]}~/src%f %F{$pure_color[grey]}master%f ${pure_use_rprompt-%F{$pure_color[yellow]\}5s%f }'
  65. '' '%F{$pure_color[magenta]}$prompt_char%f ${buffer:-$cursor}'
  66. )
  67. local -ra pure_right=(
  68. '${pure_use_rprompt+%F{$pure_color[yellow]\}5s%f${time:+ }}${time:+%F{$pure_color[grey]\}$time%f}' ''
  69. '' ''
  70. )
  71. local -ra rainbow_left=(
  72. '%$frame_color[$color]F╭─' '%F{${${extra_icons[1]:+7}:-4}}$left_tail${extra_icons[1]:+%K{7\}%232F $extra_icons[1] %K{4\}%7F$left_sep}%K{4}%254F $extra_icons[2]%B%255F~%b%K{4}%254F/%B%255Fsrc%b%K{4} %K{2}%4F$left_sep %0F$prefixes[1]$extra_icons[3]master %k%2F$left_head%f'
  73. '%$frame_color[$color]F╰─' '%f ${buffer:-$cursor}'
  74. )
  75. local -ra rainbow_right=(
  76. '%3F$right_head%K{3} %0F$prefixes[2]5s $extra_icons[4]%3F${time:+%7F$right_sep%K{7\} %0F$prefixes[3]$time $extra_icons[5]%7F}%k$right_tail%f' '%$frame_color[$color]F─╮%f'
  77. '' '%$frame_color[$color]F─╯%f'
  78. )
  79. function prompt_length() {
  80. local -i COLUMNS=1024
  81. local -i x y=$#1 m
  82. if (( y )); then
  83. while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do
  84. x=y
  85. (( y *= 2 ))
  86. done
  87. while (( y > x + 1 )); do
  88. (( m = x + (y - x) / 2 ))
  89. (( ${${(%):-$1%$m(l.x.y)}[-1]} = m ))
  90. done
  91. fi
  92. typeset -g REPLY=$x
  93. }
  94. function print_prompt() {
  95. [[ $parameters[extra_icons] == scalar* ]] && eval "local -a extra_icons=$extra_icons"
  96. [[ $parameters[pure_color] == scalar* ]] && eval "local -A pure_color=$pure_color"
  97. [[ $parameters[prefixes] == scalar* ]] && eval "local -a prefixes=$prefixes"
  98. local left=${style}_left
  99. local right=${style}_right
  100. left=("${(@P)left}")
  101. right=("${(@P)right}")
  102. (( disable_rprompt )) && right=()
  103. eval "left=(${(@)left:/(#b)(*)/\"$match[1]\"})"
  104. eval "right=(${(@)right:/(#b)(*)/\"$match[1]\"})"
  105. if (( num_lines == 1)); then
  106. left=($left[2] $left[4])
  107. right=($right[1] $right[3])
  108. else
  109. local c=76
  110. [[ $style == pure ]] && c=$pure_color[magenta]
  111. [[ $style == lean_8colors ]] && c=2
  112. (( left_frame )) || left=('' $left[2] '' "%F{$c}$prompt_char%f ${buffer:-$cursor}")
  113. (( right_frame )) || right=($right[1] '' '' '')
  114. fi
  115. local -i left_indent=prompt_indent
  116. local -i right_indent=prompt_indent
  117. prompt_length ${(g::):-$left[1]$left[2]$right[1]$right[2]}
  118. local -i width=REPLY
  119. while (( wizard_columns - width <= left_indent + right_indent )); do
  120. if (( right_indent )); then
  121. (( --right_indent ))
  122. elif (( left_indent )); then
  123. (( --left_indent ))
  124. else
  125. print -P ' [%3Fnot enough horizontal space to display this%f]'
  126. return 0
  127. fi
  128. done
  129. local -i i
  130. for ((i = 1; i < $#left; i+=2)); do
  131. local l=${(g::):-$left[i]$left[i+1]}
  132. local r=${(g::):-$right[i]$right[i+1]}
  133. prompt_length $l$r
  134. local -i gap=$((wizard_columns - left_indent - right_indent - REPLY))
  135. (( num_lines == 2 && i == 1 )) && local fill=$gap_char || local fill=' '
  136. print -n -- ${(pl:$left_indent:: :)}
  137. print -nP -- $l
  138. print -nP -- "%$frame_color[$color]F${(pl:$gap::$fill:)}%f"
  139. print -P -- $r
  140. done
  141. }
  142. function href() {
  143. local url=${${1//\%/%%}//\\/\\\\}
  144. if (( _p9k_term_has_href )); then
  145. print -r -- '%{\e]8;;'$url'\a%}'$url'%{\e]8;;\a%}'
  146. else
  147. print -r -- $url
  148. fi
  149. }
  150. function flowing() {
  151. (( ${wizard_columns:-0} )) || local -i wizard_columns=COLUMNS
  152. local opt
  153. local -i centered indentation
  154. while getopts 'ci:' opt; do
  155. case $opt in
  156. i) indentation=$OPTARG;;
  157. c) centered=1;;
  158. +c) centered=0;;
  159. \?) exit 1;;
  160. esac
  161. done
  162. shift $((OPTIND-1))
  163. local line word lines=()
  164. for word in "$@"; do
  165. prompt_length ${(g::):-"$line $word"}
  166. if (( REPLY > wizard_columns )); then
  167. [[ -z $line ]] || lines+=$line
  168. line=
  169. fi
  170. if [[ -n $line ]]; then
  171. line+=' '
  172. elif (( $#lines )); then
  173. line=${(pl:$indentation:: :)}
  174. fi
  175. line+=$word
  176. done
  177. [[ -z $line ]] || lines+=$line
  178. for line in $lines; do
  179. prompt_length ${(g::)line}
  180. (( centered && REPLY < wizard_columns )) && print -n -- ${(pl:$(((wizard_columns - REPLY) / 2)):: :)}
  181. print -P -- $line
  182. done
  183. }
  184. function clear() {
  185. if (( $+commands[clear] )) && command clear 2>/dev/null; then
  186. return
  187. fi
  188. echoti clear 2>/dev/null
  189. print -n -- "\e[H\e[2J\e[3J"
  190. }
  191. function hide_cursor() {
  192. (( $+terminfo[cnorm] )) || return
  193. echoti civis 2>/dev/null
  194. }
  195. function show_cursor() {
  196. echoti cnorm 2>/dev/null
  197. }
  198. function consume_input() {
  199. local key
  200. while true; do
  201. [[ -t 2 ]]
  202. read -t0 -k key || break
  203. done 2>/dev/null
  204. }
  205. function quit() {
  206. consume_input
  207. if [[ $1 == '-c' ]]; then
  208. print -Pr -- ''
  209. print -Pr -- '%b%k%f%u%s'
  210. print -Pr -- '%F{3}--- stack trace (most recent call first) ---%f'
  211. print -lr -- $funcfiletrace
  212. print -Pr -- '%F{3}--- end of stack trace ---%f'
  213. print -Pr -- ''
  214. print -Pr -- 'Press %BENTER%b to continue.'
  215. hide_cursor
  216. read -s
  217. fi
  218. restore_screen
  219. print
  220. if (( force )); then
  221. flowing Powerlevel10k configuration wizard has been aborted. To run it again, type:
  222. print -P ""
  223. print -P " %2Fp10k%f %Bconfigure%b"
  224. print -P ""
  225. else
  226. flowing \
  227. Powerlevel10k configuration wizard has been aborted. It will run again \
  228. next time unless you define at least one Powerlevel10k configuration option. \
  229. To define an option that does nothing except for disabling Powerlevel10k \
  230. configuration wizard, type the following command:
  231. print -P ""
  232. print -P " %2Fecho%f %3F'POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true'%f >>! $__p9k_zshrc_u"
  233. print -P ""
  234. flowing To run Powerlevel10k configuration wizard right now, type:
  235. print -P ""
  236. print -P " %2Fp10k%f %Bconfigure%b"
  237. print -P ""
  238. fi
  239. function quit() {}
  240. stty echo 2>/dev/null
  241. show_cursor
  242. exit 1
  243. }
  244. local screen_widgets=()
  245. local -i max_priority
  246. local -i prompt_idx
  247. local choice
  248. function add_widget() {
  249. local priority=$1
  250. shift
  251. local render="${(j: :)${(@q)*}}"
  252. screen_widgets+=("$priority" "$render")
  253. (( priority <= max_priority )) || max_priority=priority
  254. }
  255. function render_screen_pass() {
  256. local -i pass=$1
  257. local -i prev_pass cur_pass
  258. local prev_render cur_render
  259. for cur_pass cur_render in "${(@)screen_widgets}" 0 ''; do
  260. if (( prev_pass <= pass && (cur_pass == 0 || cur_pass > pass) )); then
  261. eval $prev_render
  262. fi
  263. prev_pass=cur_pass
  264. prev_render=$cur_render
  265. done
  266. }
  267. function get_columns() { return 'COLUMNS > 88 ? 88 : COLUMNS' }
  268. functions -M get_columns 0 0
  269. function render_screen() {
  270. {
  271. hide_cursor
  272. while true; do
  273. while true; do
  274. typeset -gi wizard_columns='get_columns()'
  275. typeset -gi wizard_lines=LINES
  276. if (( wizard_columns < __p9k_wizard_columns )); then
  277. clear
  278. flowing -c %1FNot enough horizontal space.%f
  279. print
  280. flowing Make terminal window %Bwider%b or press %BCtrl-C%b to abort Powerlevel10k configuration wizard.
  281. elif (( wizard_lines < __p9k_wizard_lines )); then
  282. clear
  283. flowing -c %1FNot enough vertical space.%f
  284. print
  285. flowing Make terminal window %Btaller%b or press %BCtrl-C%b to abort Powerlevel10k configuration wizard.
  286. else
  287. break
  288. fi
  289. while (( get_columns() == wizard_columns && LINES == wizard_lines )); do
  290. sleep 1
  291. done
  292. done
  293. local -a passes
  294. () {
  295. local -i pass
  296. local render
  297. for pass render in "${(@)screen_widgets}"; do
  298. passes+=$pass
  299. done
  300. passes=(${(onu)passes})
  301. }
  302. local -i pass
  303. for pass in $passes; do
  304. local content="$(render_screen_pass $pass)"
  305. local lines=("${(@f)content}")
  306. (( $#lines > wizard_lines )) && continue
  307. clear
  308. print -rn -- $content
  309. return 0
  310. done
  311. clear
  312. flowing -c %1FNot enough vertical space.%f
  313. print
  314. flowing Make terminal window %Btaller%b or press %BCtrl-C%b to abort Powerlevel10k configuration wizard.
  315. while (( get_columns() == wizard_columns && LINES == wizard_lines )); do
  316. sleep 1
  317. done
  318. done
  319. } always {
  320. show_cursor
  321. }
  322. }
  323. function add_prompt_n() {
  324. add_widget 0 "$@" print_prompt
  325. local var
  326. for var; do
  327. eval "local ${(q)var}"
  328. done
  329. if (( num_lines == 2 )); then
  330. add_widget $(( 100 - ++prompt_idx )) print -P ' [%3Fnot enough vertical space to display this%f]'
  331. fi
  332. }
  333. function add_prompt() {
  334. add_widget 0 print
  335. add_widget 1
  336. add_prompt_n "$@"
  337. add_widget 0 print
  338. add_widget 2
  339. }
  340. function ask() {
  341. local choices=$1
  342. local -i lines columns wizard_lines wizard_columns
  343. add_widget 0 print -P "(q) Quit and do nothing."
  344. add_widget 0 print
  345. add_widget $((max_priority + 1))
  346. add_widget 0 print -P "%BChoice [${choices}q]: %b"
  347. while true; do
  348. =true
  349. if (( LINES != lines || get_columns() != columns )); then
  350. render_screen
  351. lines=wizard_lines
  352. columns=wizard_columns
  353. fi
  354. typeset -g choice=
  355. if read -t1 -k choice; then
  356. choice=${(L)choice}
  357. if [[ $choice == q ]]; then
  358. quit
  359. fi
  360. if [[ $choices == *$choice* ]]; then
  361. screen_widgets=()
  362. max_priority=0
  363. prompt_idx=0
  364. return
  365. fi
  366. fi
  367. done
  368. }
  369. local -i greeting_printed=0
  370. function print_greeting() {
  371. (( greeting_printed )) && return
  372. if (( in_z4h_wizard )); then
  373. flowing -c %3FZsh for Humans%f uses %4FPowerlevel10k%f to print command \
  374. line prompt. This wizard will ask you a few questions and configure \
  375. prompt for you.
  376. elif (( force )); then
  377. flowing -c This is %4FPowerlevel10k configuration wizard%f. \
  378. It will ask you a few questions and configure your prompt.
  379. else
  380. flowing -c This is %4FPowerlevel10k configuration wizard%f. \
  381. You are seeing it because you haven\'t defined any \
  382. Powerlevel10k configuration options. It will ask \
  383. you a few questions and configure your prompt.
  384. fi
  385. print -P ""
  386. }
  387. function iterm_get() {
  388. /usr/libexec/PlistBuddy -c "Print :$1" ~/Library/Preferences/com.googlecode.iterm2.plist
  389. }
  390. local terminal iterm2_font_size iterm2_old_font=0 can_install_font=0
  391. () {
  392. [[ $P9K_SSH == 0 ]] || return
  393. if [[ "$(uname)" == Linux && "$(uname -o)" == Android ]]; then
  394. (( $+commands[termux-reload-settings] )) || return
  395. (( $+commands[curl] )) || return
  396. if [[ -f ~/.termux/font.ttf ]]; then
  397. [[ -r ~/.termux/font.ttf ]] || return
  398. [[ -w ~/.termux/font.ttf ]] || return
  399. ! grep -q 'MesloLGS NF' ~/.termux/font.ttf 2>/dev/null || return
  400. fi
  401. if [[ -f ~/.termux ]]; then
  402. [[ -d ~/.termux && -w ~/.termux ]] || return
  403. else
  404. [[ -w ~ ]] || return
  405. fi
  406. terminal=Termux
  407. return 0
  408. fi
  409. if [[ "$(uname)" == Darwin && $TERM_PROGRAM == iTerm.app ]]; then
  410. (( $+commands[curl] )) || return
  411. [[ $TERM_PROGRAM_VERSION == [2-9]* ]] || return
  412. if [[ -f ~/Library/Fonts ]]; then
  413. [[ -d ~/Library/Fonts && -w ~/Library/Fonts ]] || return
  414. else
  415. [[ -d ~/Library && -w ~/Library ]] || return
  416. fi
  417. [[ -x /usr/libexec/PlistBuddy ]] || return
  418. [[ -x /usr/bin/plutil ]] || return
  419. [[ -x /usr/bin/defaults ]] || return
  420. [[ -f ~/Library/Preferences/com.googlecode.iterm2.plist ]] || return
  421. [[ -r ~/Library/Preferences/com.googlecode.iterm2.plist ]] || return
  422. [[ -w ~/Library/Preferences/com.googlecode.iterm2.plist ]] || return
  423. local guid1 && guid1="$(iterm_get '"Default Bookmark Guid"' 2>/dev/null)" || return
  424. local guid2 && guid2="$(iterm_get '"New Bookmarks":0:"Guid"' 2>/dev/null)" || return
  425. local font && font="$(iterm_get '"New Bookmarks":0:"Normal Font"' 2>/dev/null)" || return
  426. [[ $guid1 == $guid2 ]] || return
  427. [[ $font != 'MesloLGS-NF-Regular '<-> ]] || return
  428. [[ $font == (#b)*' '(<->) ]] || return
  429. [[ $font == 'MesloLGSNer-Regular '<-> ]] && iterm2_old_font=1
  430. iterm2_font_size=$match[1]
  431. terminal=iTerm2
  432. return 0
  433. fi
  434. return 1
  435. } && can_install_font=1
  436. function run_command() {
  437. local msg=$1
  438. shift
  439. [[ -n $msg ]] && print -nP -- "$msg ..."
  440. local err && err="$("$@" 2>&1)" || {
  441. print -P " %1FERROR%f"
  442. print -P ""
  443. print -nP "%BCommand:%b "
  444. print -r -- "${(@q)*}"
  445. if [[ -n $err ]]; then
  446. print -P ""
  447. print -r -- $err
  448. fi
  449. quit -c
  450. }
  451. [[ -n $msg ]] && print -P " %2FOK%f"
  452. }
  453. function install_font() {
  454. clear
  455. case $terminal in
  456. Termux)
  457. command mkdir -p -- ~/.termux || quit -c
  458. run_command "Downloading %BMesloLGS NF Regular.ttf%b" \
  459. curl -fsSL -o ~/.termux/font.ttf "$font_base_url/MesloLGS%20NF%20Regular.ttf"
  460. run_command "Reloading %BTermux%b settings" termux-reload-settings
  461. ;;
  462. iTerm2)
  463. command mkdir -p -- ~/Library/Fonts || quit -c
  464. local style
  465. for style in Regular Bold Italic 'Bold Italic'; do
  466. local file="MesloLGS NF ${style}.ttf"
  467. run_command "Downloading %B$file%b" \
  468. curl -fsSL -o ~/Library/Fonts/$file.tmp "$font_base_url/${file// /%20}"
  469. command mv -f -- ~/Library/Fonts/$file{.tmp,} || quit -c
  470. done
  471. print -nP -- "Changing %BiTerm2%b settings ..."
  472. local size=$iterm2_font_size
  473. [[ $size == 12 ]] && size=13
  474. local k t v settings=(
  475. '"Normal Font"' string '"MesloLGS-NF-Regular '$size'"'
  476. '"Terminal Type"' string '"xterm-256color"'
  477. '"Horizontal Spacing"' real 1
  478. '"Vertical Spacing"' real 1
  479. '"Minimum Contrast"' real 0
  480. '"Use Bold Font"' bool 1
  481. '"Use Bright Bold"' bool 1
  482. '"Use Italic Font"' bool 1
  483. '"ASCII Anti Aliased"' bool 1
  484. '"Non-ASCII Anti Aliased"' bool 1
  485. '"Use Non-ASCII Font"' bool 0
  486. '"Ambiguous Double Width"' bool 0
  487. '"Draw Powerline Glyphs"' bool 1
  488. '"Only The Default BG Color Uses Transparency"' bool 1
  489. )
  490. for k t v in $settings; do
  491. /usr/libexec/PlistBuddy -c "Set :\"New Bookmarks\":0:$k $v" \
  492. ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null && continue
  493. run_command "" /usr/libexec/PlistBuddy -c \
  494. "Add :\"New Bookmarks\":0:$k $t $v" ~/Library/Preferences/com.googlecode.iterm2.plist
  495. done
  496. print -P " %2FOK%f"
  497. print -nP "Updating %BiTerm2%b settings cache ..."
  498. run_command "" /usr/bin/defaults read com.googlecode.iterm2
  499. sleep 3
  500. print -P " %2FOK%f"
  501. sleep 1
  502. clear
  503. hide_cursor
  504. print
  505. flowing +c "%2FMeslo Nerd Font%f" successfully installed.
  506. print -P ""
  507. () {
  508. local out
  509. out=$(/usr/bin/defaults read 'Apple Global Domain' NSQuitAlwaysKeepsWindows 2>/dev/null) || return
  510. [[ $out == 1 ]] || return
  511. out="$(iterm_get OpenNoWindowsAtStartup 2>/dev/null)" || return
  512. [[ $out == false ]]
  513. }
  514. if (( $? )); then
  515. flowing +c Please "%Brestart iTerm2%b" for the changes to take effect.
  516. print -P ""
  517. flowing +c -i 5 " 1. Click" "%BiTerm2 → Quit iTerm2%b" or press "%B⌘ Q%b."
  518. flowing +c -i 5 " 2. Open %BiTerm2%b."
  519. print -P ""
  520. flowing +c "It's" important to "%Brestart iTerm2%b" by following the instructions above. \
  521. "It's" "%Bnot enough%b" to close iTerm2 by clicking on the red circle. You must \
  522. click "%BiTerm2 → Quit iTerm2%b" or press "%B⌘ Q%b."
  523. else
  524. flowing +c Please "%Brestart your computer%b" for the changes to take effect.
  525. fi
  526. while true; do sleep 60 2>/dev/null; done
  527. ;;
  528. esac
  529. return 0
  530. }
  531. function ask_font() {
  532. (( can_install_font )) || return 0
  533. add_widget 0 print_greeting
  534. if (( iterm2_old_font )); then
  535. add_widget 0 flowing -c A new version of '%2FMeslo Nerd Font%f' is available. '%BInstall?%b'
  536. else
  537. add_widget 0 flowing -c %BInstall '%b%2FMeslo Nerd Font%f%B?%b'
  538. fi
  539. add_widget 0 print
  540. add_widget 0 print -P "%B(y) Yes (recommended).%b"
  541. add_widget 0 print
  542. add_widget 1
  543. add_widget 0 print -P "%B(n) No. Use the current font.%b"
  544. add_widget 0 print
  545. add_widget 1
  546. ask yn
  547. greeting_printed=1
  548. case $choice in
  549. y)
  550. ask_remove_font || return
  551. install_font
  552. ;;
  553. n) ;;
  554. esac
  555. return 0
  556. }
  557. function print_file_path() {
  558. local file=$1
  559. if (( ${(m)#file} > wizard_columns - 2 )); then
  560. file[wizard_columns-4,-1]='...'
  561. fi
  562. add_widget 0 print -P " %B${file//\%/%%}%b"
  563. }
  564. function ask_remove_font() {
  565. local font
  566. local -a fonts
  567. local -i protected
  568. for font in {,/System,~}/Library/Fonts/**/*[Mm]eslo*.(ttf|otf)(N:A); do
  569. [[ -f $font && -r $font ]] || continue
  570. [[ $font == ~/Library/Fonts/'MesloLGS NF '(Regular|Bold|Italic|Bold\ Italic).ttf ]] && continue
  571. [[ "$(<$font)" == *"MesloLGS NF"$'\0'* ]] || continue
  572. fonts+=$font
  573. [[ -w ${font:h} ]] || protected=1
  574. done
  575. (( $#fonts )) || return 0
  576. add_widget 0 flowing -c A variant of "%2FMeslo Nerd Font%f" is already installed.
  577. add_widget 0 print -P ""
  578. for font in $fonts; do
  579. add_widget 0 print_file_path $font
  580. done
  581. add_widget 0 print -P ""
  582. if (( protected )); then
  583. if (( $#fonts == 1 )); then
  584. add_widget 0 flowing Please %Bdelete%b this file and run '%2Fp10k%f %Bconfigure%b.'
  585. else
  586. add_widget 0 flowing Please %Bdelete%b these files and run '%2Fp10k%f %Bconfigure%b.'
  587. fi
  588. add_widget 0 print
  589. restore_screen
  590. local pass render
  591. for pass render in "${(@)screen_widgets}"; do
  592. (( pass == 0 )) && eval $render
  593. done
  594. exit 1
  595. fi
  596. if (( $#fonts == 1 )); then
  597. add_widget 0 flowing -c "%BDelete this file?%b"
  598. else
  599. add_widget 0 flowing -c "%BDelete these files?%b"
  600. fi
  601. add_widget 0 print -P ""
  602. add_widget 0 print -P "%B(y) Yes (recommended).%b"
  603. add_widget 0 print -P ""
  604. add_widget 0 print -P "(r) Restart from the beginning."
  605. ask yr
  606. case $choice in
  607. r) return 1;;
  608. y) zf_rm -f -- $fonts || quit -c;;
  609. esac
  610. return 0
  611. }
  612. function ask_diamond() {
  613. local extra
  614. add_widget 0 print_greeting
  615. add_widget 0 flowing -c %BDoes this look like a%b %2Fdiamond%f '%B(rotated square)?%b'
  616. add_widget 0 flowing -c reference: "$(href https://graphemica.com/%E2%97%86)"
  617. add_widget 0 print
  618. add_widget 0 flowing -c -- "---> \uE0B2\uE0B0 <---"
  619. add_widget 0 print
  620. add_widget 3
  621. add_widget 0 print -P "%B(y) Yes.%b"
  622. add_widget 0 print
  623. add_widget 1
  624. add_widget 0 print -P "%B(n) No.%b"
  625. add_widget 0 print
  626. add_widget 2
  627. if (( can_install_font )); then
  628. extra+=r
  629. add_widget 0 print -P "(r) Restart from the beginning."
  630. fi
  631. ask yn$extra
  632. greeting_printed=1
  633. case $choice in
  634. r) return 1;;
  635. y) cap_diamond=1;;
  636. n) cap_diamond=0;;
  637. esac
  638. return 0
  639. }
  640. function ask_lock() {
  641. [[ -n $2 ]] && add_widget 0 flowing -c "$2"
  642. add_widget 0 flowing -c "%BDoes this look like a %b%2Flock%f%B?%b"
  643. add_widget 0 flowing -c "reference: $(href https://fontawesome.com/icons/lock)"
  644. add_widget 0 print
  645. add_widget 0 flowing -c -- "---> $1 <---"
  646. add_widget 0 print
  647. add_widget 3
  648. add_widget 0 print -P "%B(y) Yes.%b"
  649. add_widget 0 print
  650. add_widget 1
  651. add_widget 0 print -P "%B(n) No.%b"
  652. add_widget 0 print
  653. add_widget 2
  654. add_widget 0 print -P "(r) Restart from the beginning."
  655. ask ynr
  656. case $choice in
  657. r) return 1;;
  658. y) cap_lock=1;;
  659. n) cap_lock=0;;
  660. esac
  661. return 0
  662. }
  663. function ask_python() {
  664. add_widget 0 flowing -c %BDoes this look like a "%b%2FPython logo%f%B?%b"
  665. add_widget 0 flowing -c reference: "$(href https://fontawesome.com/icons/python)"
  666. add_widget 0 print -P ""
  667. add_widget 0 flowing -c -- "---> \uE63C <---"
  668. add_widget 0 print -P ""
  669. add_widget 3
  670. add_widget 0 print -P "%B(y) Yes.%b"
  671. add_widget 0 print -P ""
  672. add_widget 1
  673. add_widget 0 print -P "%B(n) No.%b"
  674. add_widget 0 print -P ""
  675. add_widget 2
  676. add_widget 0 print -P "(r) Restart from the beginning."
  677. ask ynr
  678. case $choice in
  679. r) return 1;;
  680. y) cap_python=1;;
  681. n) cap_python=0;;
  682. esac
  683. return 0
  684. }
  685. function ask_arrow() {
  686. add_widget 0 flowing -c %BDoes this look like%b "%2F><%f" %Bbut taller and "fatter?%b"
  687. add_widget 0 print -P ""
  688. add_widget 0 flowing -c -- "---> \u276F\u276E <---"
  689. add_widget 0 print -P ""
  690. add_widget 3
  691. add_widget 0 print -P "%B(y) Yes.%b"
  692. add_widget 0 print -P ""
  693. add_widget 1
  694. add_widget 0 print -P "%B(n) No.%b"
  695. add_widget 0 print -P ""
  696. add_widget 2
  697. add_widget 0 print -P "(r) Restart from the beginning."
  698. ask ynr
  699. case $choice in
  700. r) return 1;;
  701. y) cap_arrow=1;;
  702. n) cap_arrow=0;;
  703. esac
  704. return 0
  705. }
  706. function ask_debian() {
  707. add_widget 0 flowing -c %BDoes this look like a%b "%2FDebian logo%f" "%B(swirl/spiral)?%b"
  708. add_widget 0 flowing -c reference: "$(href https://debian.org/logos/openlogo-nd.svg)"
  709. add_widget 0 print -P ""
  710. add_widget 0 flowing -c -- "---> \uF306 <---"
  711. add_widget 0 print -P ""
  712. add_widget 3
  713. add_widget 0 print -P "%B(y) Yes.%b"
  714. add_widget 0 print -P ""
  715. add_widget 1
  716. add_widget 0 print -P "%B(n) No.%b"
  717. add_widget 0 print -P ""
  718. add_widget 2
  719. add_widget 0 print -P "(r) Restart from the beginning."
  720. ask ynr
  721. case $choice in
  722. r) return 1;;
  723. y) cap_debian=1;;
  724. n) cap_debian=0;;
  725. esac
  726. return 0
  727. }
  728. function ask_icon_padding() {
  729. if [[ $POWERLEVEL9K_MODE == (powerline|compatible|ascii) ]]; then
  730. POWERLEVEL9K_ICON_PADDING=none
  731. return 0
  732. fi
  733. local text="X"
  734. text+="%1F${icons[VCS_GIT_ICON]// }%fX"
  735. text+="%2F${icons[VCS_GIT_GITHUB_ICON]// }%fX"
  736. text+="%3F${icons[TIME_ICON]// }%fX"
  737. text+="%4F${icons[RUBY_ICON]// }%fX"
  738. text+="%5F${icons[HOME_ICON]// }%fX"
  739. text+="%6F${icons[HOME_SUB_ICON]// }%fX"
  740. text+="%1F${icons[FOLDER_ICON]// }%fX"
  741. text+="%2F${icons[RAM_ICON]// }%fX"
  742. add_widget 0 flowing -c %BDo all these icons "%b%2Ffit between the crosses%f%B?%b"
  743. add_widget 0 print -P ""
  744. add_widget 0 flowing -c -- "---> $text <---"
  745. add_widget 0 print -P ""
  746. add_widget 3
  747. add_widget 0 flowing +c -i 5 "%B(y) Yes." Icons are very close to the crosses but there is "%b%2Fno overlap%f%B.%b"
  748. add_widget 0 print -P ""
  749. add_widget 1
  750. add_widget 0 flowing +c -i 5 "%B(n) No." Some icons "%b%2Foverlap%f%B" neighbouring crosses.%b
  751. add_widget 0 print -P ""
  752. add_widget 2
  753. add_widget 0 print -P "(r) Restart from the beginning."
  754. ask ynr
  755. case $choice in
  756. r) return 1;;
  757. y)
  758. POWERLEVEL9K_ICON_PADDING=none
  759. options+='small icons'
  760. ;;
  761. n)
  762. POWERLEVEL9K_ICON_PADDING=moderate
  763. options+='large icons'
  764. up_triangle+=' '
  765. down_triangle+=' '
  766. slanted_bar='\uE0BD '
  767. ;;
  768. esac
  769. return 0
  770. }
  771. function ask_style() {
  772. if (( terminfo[colors] < 256 )); then
  773. style=lean_8colors
  774. left_frame=0
  775. right_frame=0
  776. frame_color=(0 7 2 4)
  777. color_name=(Black White Green Blue)
  778. options+=lean_8colors
  779. return 0
  780. fi
  781. local extra
  782. add_widget 0 flowing -c "%BPrompt Style%b"
  783. add_widget 0 print
  784. add_widget 1
  785. add_widget 0 print -P "%B(1) Lean.%b"
  786. add_prompt style=lean left_frame=0 right_frame=0
  787. add_widget 0 print -P "%B(2) Classic.%b"
  788. add_prompt style=classic
  789. add_widget 0 print -P "%B(3) Rainbow.%b"
  790. add_prompt style=rainbow
  791. if [[ $POWERLEVEL9K_MODE != ascii ]]; then
  792. extra+=4
  793. add_widget 0 print -P "%B(4) Pure.%b"
  794. add_prompt style=pure
  795. fi
  796. add_widget 0 print -P "(r) Restart from the beginning."
  797. ask 123${extra}r
  798. case $choice in
  799. r) return 1;;
  800. 1) style=lean; left_frame=0; right_frame=0; options+=lean;;
  801. 2) style=classic; options+=classic;;
  802. 3) style=rainbow; options+=rainbow;;
  803. 4) style=pure; empty_line=1; options+=pure;;
  804. esac
  805. return 0
  806. }
  807. function ask_charset() {
  808. [[ $style == (lean*|classic|rainbow) && $POWERLEVEL9K_MODE != ascii ]] || return 0
  809. add_widget 0 flowing -c "%BCharacter Set%b"
  810. add_widget 0 print -P ""
  811. add_widget 1
  812. add_widget 0 print -P "%B(1) Unicode.%b"
  813. add_prompt
  814. add_widget 0 print -P "%B(2) ASCII.%b"
  815. add_prompt \
  816. left_sep= \
  817. right_sep= \
  818. left_subsep='|' \
  819. right_subsep='|' \
  820. left_head= \
  821. right_head= \
  822. prompt_char='>' \
  823. left_frame=0 \
  824. right_frame=0
  825. add_widget 0 print -P "(r) Restart from the beginning."
  826. ask 12r
  827. case $choice in
  828. r) return 1;;
  829. 1) options+=unicode;;
  830. 2)
  831. options+=ascii
  832. left_sep=
  833. right_sep=
  834. left_subsep='|'
  835. right_subsep='|'
  836. left_head=
  837. right_head=
  838. prompt_char='>'
  839. left_frame=0
  840. right_frame=0
  841. POWERLEVEL9K_MODE=ascii
  842. POWERLEVEL9K_ICON_PADDING=none
  843. cap_diamond=0
  844. cap_python=0
  845. cap_debian=0
  846. cap_lock=0
  847. cap_arrow=0
  848. ;;
  849. esac
  850. return 0
  851. }
  852. function ask_color_scheme() {
  853. (( terminfo[colors] < 256 )) && return
  854. if [[ $style == lean ]]; then
  855. add_widget 0 flowing -c "%BPrompt Colors%b"
  856. add_widget 0 print -P ""
  857. add_widget 1
  858. add_widget 0 print -P "%B(1) 256 colors.%b"
  859. add_prompt style=lean
  860. add_widget 0 print -P "%B(2) 8 colors.%b"
  861. add_prompt style=lean_8colors
  862. add_widget 0 print -P "(r) Restart from the beginning."
  863. ask 12r
  864. case $choice in
  865. r) return 1;;
  866. 1) style=lean;;
  867. 2)
  868. style=lean_8colors
  869. frame_color=(0 7 2 4)
  870. color_name=(Black White Green Blue)
  871. ;;
  872. esac
  873. options=(${options:#lean} $style)
  874. elif [[ $style == pure && $has_truecolor == 1 ]]; then
  875. add_widget 0 flowing -c "%BPrompt Colors%b"
  876. add_widget 0 print -P ""
  877. add_widget 1
  878. add_widget 0 print -P "%B(1) Original.%b"
  879. add_prompt "pure_color=(${(j: :)${(@q)${(@kv)pure_original}}})"
  880. add_widget 0 print -P "%B(2) Snazzy.%b"
  881. add_prompt "pure_color=(${(j: :)${(@q)${(@kv)pure_snazzy}}})"
  882. add_widget 0 print -P "(r) Restart from the beginning."
  883. ask 12r
  884. case $choice in
  885. r) return 1;;
  886. 1)
  887. pure_color=(${(kv)pure_original})
  888. options+=original
  889. ;;
  890. 2)
  891. pure_color=(${(kv)pure_snazzy})
  892. options+=snazzy
  893. ;;
  894. esac
  895. fi
  896. return 0
  897. }
  898. function ask_color() {
  899. [[ $style != classic ]] && return
  900. add_widget 0 flowing -c "%BPrompt Color%b"
  901. add_widget 0 print
  902. add_widget 1
  903. add_widget 0 print -P "%B(1) $color_name[1].%b"
  904. add_prompt color=1
  905. add_widget 0 print -P "%B(2) $color_name[2].%b"
  906. add_prompt color=2
  907. add_widget 0 print -P "%B(3) $color_name[3].%b"
  908. add_prompt color=3
  909. add_widget 0 print -P "%B(4) $color_name[4].%b"
  910. add_prompt color=4
  911. add_widget 0 print -P "(r) Restart from the beginning."
  912. ask 1234r
  913. case $choice in
  914. r) return 1;;
  915. [1-4]) color=$choice;;
  916. esac
  917. options+=${${(L)color_name[color]}//ı/i}
  918. return 0
  919. }
  920. function ask_ornaments_color() {
  921. [[ $style != (rainbow|lean*) || $num_lines == 1 ]] && return
  922. [[ $gap_char == ' ' && $left_frame == 0 && $right_frame == 0 ]] && return
  923. local ornaments=()
  924. [[ $gap_char != ' ' ]] && ornaments+=Connection
  925. (( left_frame || right_frame )) && ornaments+=Frame
  926. add_widget 0 flowing -c "%B${(j: & :)ornaments} Color%b"
  927. add_widget 0 print
  928. add_widget 1
  929. add_widget 0 print -P "%B(1) $color_name[1].%b"
  930. add_prompt color=1
  931. add_widget 0 print -P "%B(2) $color_name[2].%b"
  932. add_prompt color=2
  933. add_widget 0 print -P "%B(3) $color_name[3].%b"
  934. add_prompt color=3
  935. add_widget 0 print -P "%B(4) $color_name[4].%b"
  936. add_prompt color=4
  937. add_widget 0 print -P "(r) Restart from the beginning."
  938. ask 1234r
  939. case $choice in
  940. r) return 1;;
  941. [1-4]) color=$choice;;
  942. esac
  943. options+=${${(L)color_name[color]}//ı/i}-ornaments
  944. return 0
  945. }
  946. function ask_time() {
  947. local extra
  948. add_widget 0 flowing -c "%BShow current time?%b"
  949. add_widget 0 print
  950. add_widget 1
  951. add_widget 0 print -P "%B(1) No.%b"
  952. add_prompt time=
  953. add_widget 0 print -P "%B(2) 24-hour format.%b"
  954. add_prompt time=$time_24h
  955. add_widget 0 print -P "%B(3) 12-hour format.%b"
  956. add_prompt time=$time_12h
  957. add_widget 0 print -P "(r) Restart from the beginning."
  958. ask 123r
  959. case $choice in
  960. r) return 1;;
  961. 1) time=;;
  962. 2) time=$time_24h; options+='24h time';;
  963. 3) time=$time_12h; options+='12h time';;
  964. esac
  965. return 0
  966. }
  967. function ask_use_rprompt() {
  968. [[ $style != pure ]] && return
  969. add_widget 0 flowing -c "%BNon-permanent content location%b"
  970. add_widget 0 print
  971. add_widget 1
  972. add_widget 0 print -P "%B(1) Left.%b"
  973. add_prompt
  974. add_widget 0 print -P "%B(2) Right.%b"
  975. add_prompt pure_use_rprompt=
  976. add_widget 0 print -P "(r) Restart from the beginning."
  977. ask 12r
  978. case $choice in
  979. r) return 1;;
  980. 1) ;;
  981. 2) pure_use_rprompt=; options+=rprompt;;
  982. esac
  983. return 0
  984. }
  985. function os_icon_name() {
  986. local uname="$(uname)"
  987. if [[ $uname == Linux && "$(uname -o 2>/dev/null)" == Android ]]; then
  988. echo ANDROID_ICON
  989. else
  990. case $uname in
  991. SunOS) echo SUNOS_ICON;;
  992. Darwin) echo APPLE_ICON;;
  993. CYGWIN_NT-*|MSYS_NT-*|MINGW64_NT-*|MINGW32_NT-*) echo WINDOWS_ICON;;
  994. FreeBSD|OpenBSD|DragonFly) echo FREEBSD_ICON;;
  995. Linux)
  996. local os_release_id
  997. if [[ -r /etc/os-release ]]; then
  998. local lines=(${(f)"$(</etc/os-release)"})
  999. lines=(${(@M)lines:#ID=*})
  1000. (( $#lines == 1 )) && os_release_id=${lines[1]#ID=}
  1001. elif [[ -e /etc/artix-release ]]; then
  1002. os_release_id=artix
  1003. fi
  1004. case $os_release_id in
  1005. *arch*) echo LINUX_ARCH_ICON;;
  1006. *debian*) echo LINUX_DEBIAN_ICON;;
  1007. *raspbian*) echo LINUX_RASPBIAN_ICON;;
  1008. *ubuntu*) echo LINUX_UBUNTU_ICON;;
  1009. *elementary*) echo LINUX_ELEMENTARY_ICON;;
  1010. *fedora*) echo LINUX_FEDORA_ICON;;
  1011. *coreos*) echo LINUX_COREOS_ICON;;
  1012. *gentoo*) echo LINUX_GENTOO_ICON;;
  1013. *mageia*) echo LINUX_MAGEIA_ICON;;
  1014. *centos*) echo LINUX_CENTOS_ICON;;
  1015. *opensuse*|*tumbleweed*) echo LINUX_OPENSUSE_ICON;;
  1016. *sabayon*) echo LINUX_SABAYON_ICON;;
  1017. *slackware*) echo LINUX_SLACKWARE_ICON;;
  1018. *linuxmint*) echo LINUX_MINT_ICON;;
  1019. *alpine*) echo LINUX_ALPINE_ICON;;
  1020. *aosc*) echo LINUX_AOSC_ICON;;
  1021. *nixos*) echo LINUX_NIXOS_ICON;;
  1022. *devuan*) echo LINUX_DEVUAN_ICON;;
  1023. *manjaro*) echo LINUX_MANJARO_ICON;;
  1024. *void*) echo LINUX_VOID_ICON;;
  1025. *artix*) echo LINUX_ARTIX_ICON;;
  1026. *rhel*) echo LINUX_RHEL_ICON;;
  1027. amzn) echo LINUX_AMZN_ICON;;
  1028. *) echo LINUX_ICON;;
  1029. esac
  1030. ;;
  1031. esac
  1032. fi
  1033. }
  1034. function ask_extra_icons() {
  1035. if [[ $style == pure || $POWERLEVEL9K_MODE == (powerline|compatible|ascii) ]]; then
  1036. return 0
  1037. fi
  1038. local os_icon=${(g::)icons[$(os_icon_name)]}
  1039. local dir_icon=${(g::)icons[HOME_SUB_ICON]}
  1040. local vcs_icon=${(g::)icons[VCS_GIT_GITHUB_ICON]}
  1041. local branch_icon=${(g::)icons[VCS_BRANCH_ICON]}
  1042. local duration_icon=${(g::)icons[EXECUTION_TIME_ICON]}
  1043. local time_icon=${(g::)icons[TIME_ICON]}
  1044. branch_icon=${branch_icon// }
  1045. local few=('' '' '' '' '')
  1046. local many=("$os_icon" "$dir_icon " "$vcs_icon $branch_icon " "$duration_icon " "$time_icon ")
  1047. add_widget 0 flowing -c "%BIcons%b"
  1048. add_widget 0 print
  1049. add_widget 1
  1050. add_widget 0 print -P "%B(1) Few icons.%b"
  1051. add_prompt "extra_icons=(${(j: :)${(@q)few}})"
  1052. add_widget 0 print -P "%B(2) Many icons.%b"
  1053. add_prompt "extra_icons=(${(j: :)${(@q)many}})"
  1054. add_widget 0 print -P "(r) Restart from the beginning."
  1055. ask 12r
  1056. case $choice in
  1057. r) return 1;;
  1058. 1) extra_icons=("$few[@]"); options+='few icons';;
  1059. 2) extra_icons=("$many[@]"); options+='many icons';;
  1060. esac
  1061. return 0
  1062. }
  1063. function ask_prefixes() {
  1064. if [[ $style == pure ]]; then
  1065. return 0
  1066. fi
  1067. local concise=('' '' '')
  1068. local fluent=('on ' 'took ' 'at ')
  1069. add_widget 0 flowing -c "%BPrompt Flow%b"
  1070. add_widget 0 print
  1071. add_widget 1
  1072. add_widget 0 print -P "%B(1) Concise.%b"
  1073. add_prompt "prefixes=(${(j: :)${(@q)concise}})"
  1074. add_widget 0 print -P "%B(2) Fluent.%b"
  1075. add_prompt "prefixes=(${(j: :)${(@q)fluent}})"
  1076. add_widget 0 print -P "(r) Restart from the beginning."
  1077. ask 12r
  1078. case $choice in
  1079. r) return 1;;
  1080. 1) prefixes=("$concise[@]"); options+=concise;;
  1081. 2) prefixes=("$fluent[@]"); options+=fluent;;
  1082. esac
  1083. return 0
  1084. }
  1085. function ask_separators() {
  1086. if [[ $style != (classic|rainbow) || $cap_diamond != 1 ]]; then
  1087. return 0
  1088. fi
  1089. local extra
  1090. add_widget 0 flowing -c "%BPrompt Separators%b"
  1091. add_widget 0 print -Pl " separator" "%B(1) Angled.%b /" " /"
  1092. add_widget 3 print -P "%B(1) Angled.%b"
  1093. add_prompt_n left_sep=$right_triangle right_sep=$left_triangle left_subsep=$right_angle right_subsep=$left_angle
  1094. add_widget 0 print
  1095. add_widget 2
  1096. add_widget 0 print -P "%B(2) Vertical.%b"
  1097. add_prompt left_sep='' right_sep='' left_subsep=$vertical_bar right_subsep=$vertical_bar
  1098. if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then
  1099. extra+=3
  1100. add_widget 0 print -P "%B(3) Slanted.%b"
  1101. add_prompt left_sep=$down_triangle right_sep=$up_triangle left_subsep=$slanted_bar right_subsep=$slanted_bar
  1102. extra+=4
  1103. add_widget 0 print -P "%B(4) Round.%b"
  1104. add_prompt left_sep=$right_circle right_sep=$left_circle left_subsep=$right_arc right_subsep=$left_arc
  1105. fi
  1106. add_widget 0 print -P "(r) Restart from the beginning."
  1107. ask 12${extra}r
  1108. case $choice in
  1109. r) return 1;;
  1110. 1)
  1111. left_sep=$right_triangle
  1112. right_sep=$left_triangle
  1113. left_subsep=$right_angle
  1114. right_subsep=$left_angle
  1115. options+='angled separators'
  1116. ;;
  1117. 2)
  1118. left_sep=''
  1119. right_sep=''
  1120. left_subsep=$vertical_bar
  1121. right_subsep=$vertical_bar
  1122. options+='vertical separators'
  1123. ;;
  1124. 3)
  1125. left_sep=$down_triangle
  1126. right_sep=$up_triangle
  1127. left_subsep=$slanted_bar
  1128. right_subsep=$slanted_bar
  1129. options+='slanted separators'
  1130. ;;
  1131. 4)
  1132. left_sep=$right_circle
  1133. right_sep=$left_circle
  1134. left_subsep=$right_arc
  1135. right_subsep=$left_arc
  1136. options+='round separators'
  1137. ;;
  1138. esac
  1139. return 0
  1140. }
  1141. function ask_heads() {
  1142. if [[ $style != (classic|rainbow) || $POWERLEVEL9K_MODE == ascii ]]; then
  1143. return 0
  1144. fi
  1145. local extra
  1146. add_widget 0 flowing -c "%BPrompt Heads%b"
  1147. if (( cap_diamond )); then
  1148. add_widget 0 print -Pl " head" "%B(1) Sharp.%b |" " v"
  1149. add_widget 3 print -P "%B(1) Sharp.%b"
  1150. add_prompt_n left_head=$right_triangle right_head=$left_triangle
  1151. add_widget 0 print
  1152. add_widget 2
  1153. else
  1154. add_widget 0 print
  1155. add_widget 1
  1156. add_widget 0 print -P "%B(1) Flat.%b"
  1157. add_prompt left_head= right_head=
  1158. fi
  1159. add_widget 0 print -P "%B(2) Blurred.%b"
  1160. add_prompt left_head=$fade_out right_head=$fade_in
  1161. if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then
  1162. extra+=3
  1163. add_widget 0 print -P "%B(3) Slanted.%b"
  1164. add_prompt left_head=$down_triangle right_head=$up_triangle
  1165. extra+=4
  1166. add_widget 0 print -P "%B(4) Round.%b"
  1167. add_prompt left_head=$right_circle right_head=$left_circle
  1168. fi
  1169. add_widget 0 print -P "(r) Restart from the beginning."
  1170. ask 12${extra}r
  1171. case $choice in
  1172. r) return 1;;
  1173. 1)
  1174. if (( cap_diamond )); then
  1175. left_head=$right_triangle
  1176. right_head=$left_triangle
  1177. options+='sharp heads'
  1178. else
  1179. left_head=
  1180. right_head=
  1181. options+='flat heads'
  1182. fi
  1183. ;;
  1184. 2)
  1185. left_head=$fade_out
  1186. right_head=$fade_in
  1187. options+='blurred heads'
  1188. ;;
  1189. 3)
  1190. left_head=$down_triangle
  1191. right_head=$up_triangle
  1192. options+='slanted heads'
  1193. ;;
  1194. 4)
  1195. left_head=$right_circle
  1196. right_head=$left_circle
  1197. options+='round heads'
  1198. ;;
  1199. esac
  1200. return 0
  1201. }
  1202. function print_tail_marker() {
  1203. local label='(1) Flat.'
  1204. local -i n='wizard_columns - 7'
  1205. local -i m=$((n - $#label))
  1206. print -P "${(l:$n:: :)}tail"
  1207. print -P "%B$label%b${(l:$m:: :)} |"
  1208. print -P "${(l:$n:: :)} v"
  1209. }
  1210. function ask_tails() {
  1211. if [[ $style != (classic|rainbow) || $POWERLEVEL9K_MODE == ascii ]]; then
  1212. return 0
  1213. fi
  1214. local extra
  1215. add_widget 0 flowing -c "%BPrompt Tails%b"
  1216. add_widget 0 print_tail_marker
  1217. add_widget 3 print -P "%B(1) Flat.%b"
  1218. add_prompt_n left_tail='' right_tail=''
  1219. add_widget 0 print
  1220. add_widget 2
  1221. add_widget 0 print -P "%B(2) Blurred.%b"
  1222. add_prompt left_tail=$fade_in right_tail=$fade_out
  1223. if (( cap_diamond )); then
  1224. extra+=3
  1225. add_widget 0 print -P "%B(3) Sharp.%b"
  1226. add_prompt left_tail=$left_triangle right_tail=$right_triangle
  1227. if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then
  1228. extra+=4
  1229. add_widget 0 print -P "%B(4) Slanted.%b"
  1230. add_prompt left_tail=$up_triangle right_tail=$down_triangle
  1231. extra+=5
  1232. add_widget 0 print -P "%B(5) Round.%b"
  1233. add_prompt left_tail=$left_circle right_tail=$right_circle
  1234. fi
  1235. fi
  1236. add_widget 0 print -P "(r) Restart from the beginning."
  1237. ask 12${extra}r
  1238. case $choice in
  1239. r) return 1;;
  1240. 1) left_tail=''; right_tail=''; options+='flat tails';;
  1241. 2) left_tail=$fade_in; right_tail=$fade_out; options+='blurred tails';;
  1242. 3)
  1243. left_tail=$left_triangle
  1244. right_tail=$right_triangle
  1245. options+='sharp tails'
  1246. ;;
  1247. 4)
  1248. left_tail=$up_triangle
  1249. right_tail=$down_triangle
  1250. options+='slanted tails'
  1251. ;;
  1252. 5)
  1253. left_tail=$left_circle
  1254. right_tail=$right_circle
  1255. options+='round tails'
  1256. ;;
  1257. esac
  1258. return 0
  1259. }
  1260. function ask_num_lines() {
  1261. add_widget 0 flowing -c "%BPrompt Height%b"
  1262. add_widget 0 print
  1263. add_widget 1
  1264. add_widget 0 print -P "%B(1) One line.%b"
  1265. add_prompt num_lines=1
  1266. add_widget 0 print -P "%B(2) Two lines.%b"
  1267. add_prompt num_lines=2
  1268. add_widget 0 print -P "(r) Restart from the beginning."
  1269. ask 12r
  1270. case $choice in
  1271. r) return 1;;
  1272. 1) num_lines=1; options+='1 line';;
  1273. 2) num_lines=2; options+='2 lines';;
  1274. esac
  1275. return 0
  1276. }
  1277. function ask_gap_char() {
  1278. [[ $num_lines != 2 || $style == pure ]] && return
  1279. if [[ $POWERLEVEL9K_MODE == ascii ]]; then
  1280. local dot='.'
  1281. local dash='-'
  1282. else
  1283. local dot='·'
  1284. local dash='─'
  1285. fi
  1286. add_widget 0 flowing -c "%BPrompt Connection%b"
  1287. add_widget 0 print
  1288. add_widget 1
  1289. add_widget 0 print -P "%B(1) Disconnected.%b"
  1290. add_prompt gap_char=" "
  1291. add_widget 0 print -P "%B(2) Dotted.%b"
  1292. add_prompt gap_char=$dot
  1293. add_widget 0 print -P "%B(3) Solid.%b"
  1294. add_prompt gap_char=$dash
  1295. add_widget 0 print -P "(r) Restart from the beginning."
  1296. ask 123r
  1297. case $choice in
  1298. r) return 1;;
  1299. 1) gap_char=" "; options+=disconnected;;
  1300. 2) gap_char=$dot; options+=dotted;;
  1301. 3) gap_char=$dash; options+=solid;;
  1302. esac
  1303. return 0
  1304. }
  1305. function ask_frame() {
  1306. if [[ $style != (classic|rainbow|lean*) || $num_lines != 2 || $POWERLEVEL9K_MODE == ascii ]]; then
  1307. return 0
  1308. fi
  1309. add_widget 0 flowing -c "%BPrompt Frame%b"
  1310. add_widget 0 print
  1311. add_widget 1
  1312. add_widget 0 print -P "%B(1) No frame.%b"
  1313. add_prompt left_frame=0 right_frame=0
  1314. add_widget 0 print -P "%B(2) Left.%b"
  1315. add_prompt left_frame=1 right_frame=0
  1316. add_widget 0 print -P "%B(3) Right.%b"
  1317. add_prompt left_frame=0 right_frame=1
  1318. add_widget 0 print -P "%B(4) Full.%b"
  1319. add_prompt left_frame=1 right_frame=1
  1320. add_widget 0 print -P "(r) Restart from the beginning."
  1321. ask 1234r
  1322. case $choice in
  1323. r) return 1;;
  1324. 1) left_frame=0; right_frame=0; options+='no frame';;
  1325. 2) left_frame=1; right_frame=0; options+='left frame';;
  1326. 3) left_frame=0; right_frame=1; options+='right frame';;
  1327. 4) left_frame=1; right_frame=1; options+='full frame';;
  1328. esac
  1329. return 0
  1330. }
  1331. function ask_empty_line() {
  1332. add_widget 0 flowing -c "%BPrompt Spacing%b"
  1333. add_widget 0 print
  1334. add_widget 1
  1335. add_widget 0 print -P "%B(1) Compact.%b"
  1336. add_widget 0 print
  1337. add_widget 1
  1338. add_prompt_n
  1339. add_prompt_n
  1340. add_widget 0 print
  1341. add_widget 2
  1342. add_widget 0 print -P "%B(2) Sparse.%b"
  1343. add_widget 0 print
  1344. add_widget 1
  1345. add_prompt_n
  1346. add_widget 0 print
  1347. add_prompt_n
  1348. add_widget 0 print
  1349. add_widget 2
  1350. add_widget 0 print -P "(r) Restart from the beginning."
  1351. ask 12r
  1352. case $choice in
  1353. r) return 1;;
  1354. 1) empty_line=0; options+='compact';;
  1355. 2) empty_line=1; options+='sparse';;
  1356. esac
  1357. return 0
  1358. }
  1359. function print_instant_prompt_link() {
  1360. local link='https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt'
  1361. (( wizard_columns < $#link )) && return
  1362. print
  1363. flowing -c "$(href $link)"
  1364. }
  1365. function ask_instant_prompt() {
  1366. if ! is-at-least 5.4; then
  1367. instant_prompt=off
  1368. options+=instant_prompt=auto-off
  1369. return 0
  1370. fi
  1371. if (( $+functions[z4h] )); then
  1372. instant_prompt=quiet
  1373. options+=instant_prompt=auto-quiet
  1374. return
  1375. fi
  1376. add_widget 0 flowing -c "%BInstant Prompt Mode%b"
  1377. add_widget 0 print_instant_prompt_link
  1378. add_widget 1
  1379. add_widget 0 print
  1380. add_widget 2
  1381. add_widget 0 flowing +c -i 5 "%B(1) Verbose (recommended).%b"
  1382. add_widget 0 print
  1383. add_widget 1
  1384. add_widget 0 flowing +c -i 5 "%B(2) Quiet.%b" Choose this if you\'ve read and understood \
  1385. instant prompt documentation.
  1386. add_widget 0 print
  1387. add_widget 1
  1388. add_widget 0 flowing +c -i 5 "%B(3) Off.%b" Choose this if you\'ve tried instant prompt \
  1389. and found it incompatible with your zsh configuration files.
  1390. add_widget 0 print
  1391. add_widget 2
  1392. add_widget 0 print -P "(r) Restart from the beginning."
  1393. ask 123r
  1394. case $choice in
  1395. r) return 1;;
  1396. 1) instant_prompt=verbose; options+=instant_prompt=verbose;;
  1397. 2) instant_prompt=quiet; options+=instant_prompt=quiet;;
  1398. 3) instant_prompt=off; options+=instant_prompt=off;;
  1399. esac
  1400. return 0
  1401. }
  1402. function ask_transient_prompt() {
  1403. local disable_rprompt=$((num_lines == 1))
  1404. local p=76
  1405. [[ $style == pure ]] && p=$pure_color[magenta]
  1406. [[ $style == lean_8colors ]] && p=2
  1407. p="%F{$p}$prompt_char%f"
  1408. add_widget 0 flowing -c "%BEnable Transient Prompt?%b"
  1409. add_widget 0 print
  1410. add_widget 1
  1411. add_widget 0 print -P "%B(y) Yes.%b"
  1412. add_widget 0 print
  1413. add_widget 1
  1414. add_widget 0 print -P "${(pl:$prompt_indent:: :)}$p %2Fgit%f pull"
  1415. add_widget 3
  1416. add_widget 0 print -P "${(pl:$prompt_indent:: :)}$p %2Fgit%f branch x"
  1417. (( empty_line )) && add_widget 0 print
  1418. add_prompt_n buffer="%2Fgit%f checkout x$cursor"
  1419. add_widget 0 print
  1420. add_widget 2
  1421. add_widget 0 print -P "%B(n) No.%b"
  1422. add_widget 0 print
  1423. add_widget 1
  1424. add_widget 0 buffer="%2Fgit%f pull" print_prompt
  1425. add_widget 3
  1426. (( empty_line )) && { add_widget 0 print; add_widget 3 }
  1427. add_prompt_n buffer="%2Fgit%f branch x"
  1428. (( empty_line )) && add_widget 0 print
  1429. add_prompt_n buffer="%2Fgit%f checkout x$cursor"
  1430. add_widget 0 print
  1431. add_widget 2
  1432. add_widget 0 print -P "(r) Restart from the beginning."
  1433. ask ynr
  1434. case $choice in
  1435. r) return 1;;
  1436. y) transient_prompt=1; options+=transient_prompt;;
  1437. n) transient_prompt=0;;
  1438. esac
  1439. return 0
  1440. }
  1441. function ask_config_overwrite() {
  1442. config_backup=
  1443. config_backup_u=0
  1444. if [[ ! -e $__p9k_cfg_path ]]; then
  1445. return 0
  1446. fi
  1447. add_widget 0 flowing -c Powerlevel10k config file already exists.
  1448. add_widget 0 flowing -c "%BOverwrite" "%b%2F${__p9k_cfg_path_u//\\/\\\\}%f%B?%b"
  1449. add_widget 0 print -P ""
  1450. add_widget 0 print -P "%B(y) Yes.%b"
  1451. add_widget 0 print -P ""
  1452. add_widget 0 print -P "(r) Restart from the beginning."
  1453. ask yr
  1454. case $choice in
  1455. r) return 1;;
  1456. y)
  1457. config_backup="$(mktemp ${TMPDIR:-/tmp}/$__p9k_cfg_basename.XXXXXXXXXX)" || quit -c
  1458. cp $__p9k_cfg_path $config_backup || quit -c
  1459. config_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)config_backup:t}
  1460. ;;
  1461. esac
  1462. return 0
  1463. }
  1464. function ask_zshrc_edit() {
  1465. zshrc_content=
  1466. zshrc_backup=
  1467. zshrc_backup_u=
  1468. zshrc_has_cfg=0
  1469. zshrc_has_instant_prompt=0
  1470. write_zshrc=0
  1471. if (( $+functions[z4h] )); then
  1472. zshrc_has_cfg=1
  1473. zshrc_has_instant_prompt=1
  1474. return
  1475. fi
  1476. check_zshrc_integration || quit -c
  1477. [[ $instant_prompt == off ]] && zshrc_has_instant_prompt=1
  1478. (( zshrc_has_cfg && zshrc_has_instant_prompt )) && return
  1479. add_widget 0 flowing -c %BApply changes to "%b%2F${__p9k_zshrc_u//\\/\\\\}%f%B?%b"
  1480. add_widget 0 print -P ""
  1481. add_widget 1
  1482. local modifiable=y
  1483. if [[ ! -w $__p9k_zd ]]; then
  1484. modifiable=
  1485. add_widget 0 flowing -c %3FWARNING:%f %2F${__p9k_zd_u//\\/\\\\}%f %3Fis readonly.%f
  1486. add_widget 0 print -P ""
  1487. elif [[ -e $__p9k_zshrc && ! -w $__p9k_zshrc ]]; then
  1488. local -a stat
  1489. zstat -A stat +uid -- $__p9k_zshrc || quit -c
  1490. if (( stat[1] == EUID )); then
  1491. add_widget 0 flowing -c %3FNOTE:%f %2F${__p9k_zshrc_u//\\/\\\\}%f %3Fis readonly.%f
  1492. else
  1493. modifiable=
  1494. add_widget 0 flowing -c \
  1495. %3FWARNING:%f %2F${__p9k_zshrc_u//\\/\\\\}%f %3Fis readonly and \
  1496. not owned by the user. Cannot modify it.%f
  1497. fi
  1498. add_widget 0 print -P ""
  1499. fi
  1500. if [[ $modifiable == y ]]; then
  1501. add_widget 0 print -P "%B(y) Yes (recommended).%b"
  1502. else
  1503. add_widget 0 print -P "%1F(y) Yes (disabled).%f"
  1504. fi
  1505. add_widget 0 print -P ""
  1506. add_widget 0 flowing +c -i 5 "%B(n) No." I know which changes to apply and will do it myself.%b
  1507. add_widget 0 print -P ""
  1508. add_widget 0 print -P "(r) Restart from the beginning."
  1509. ask ${modifiable}nr
  1510. case $choice in
  1511. r) return 1;;
  1512. n) return 0;;
  1513. y)
  1514. write_zshrc=1
  1515. if [[ -n $zshrc_content ]]; then
  1516. zshrc_backup="$(mktemp ${TMPDIR:-/tmp}/.zshrc.XXXXXXXXXX)" || quit -c
  1517. cp -p $__p9k_zshrc $zshrc_backup || quit -c
  1518. local -i writable=1
  1519. if [[ ! -w $zshrc_backup ]]; then
  1520. chmod u+w -- $zshrc_backup || quit -c
  1521. writable=0
  1522. fi
  1523. print -r -- $zshrc_content >$zshrc_backup || quit -c
  1524. (( writable )) || chmod u-w -- $zshrc_backup || quit -c
  1525. zshrc_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)zshrc_backup:t}
  1526. fi
  1527. ;;
  1528. esac
  1529. return 0
  1530. }
  1531. function generate_config() {
  1532. local base && base="$(<$__p9k_root_dir/config/p10k-${style//_/-}.zsh)" || return
  1533. local lines=("${(@f)base}")
  1534. function sub() {
  1535. lines=("${(@)lines/#(#b)([[:space:]]#)typeset -g POWERLEVEL9K_$1=*/$match[1]typeset -g POWERLEVEL9K_$1=$2}")
  1536. }
  1537. function uncomment() {
  1538. lines=("${(@)lines/#(#b)([[:space:]]#)\# $1( |)/$match[1]$1$match[2]$match[2]}")
  1539. }
  1540. function rep() {
  1541. lines=("${(@)lines//$1/$2}")
  1542. }
  1543. if [[ $style == pure ]]; then
  1544. rep "local grey=242" "local grey='$pure_color[grey]'"
  1545. rep "local red=1" "local red='$pure_color[red]'"
  1546. rep "local yellow=3" "local yellow='$pure_color[yellow]'"
  1547. rep "local blue=4" "local blue='$pure_color[blue]'"
  1548. rep "local magenta=5" "local magenta='$pure_color[magenta]'"
  1549. rep "local cyan=6" "local cyan='$pure_color[cyan]'"
  1550. rep "local white=7" "local white='$pure_color[white]'"
  1551. else
  1552. sub MODE $POWERLEVEL9K_MODE
  1553. sub ICON_PADDING $POWERLEVEL9K_ICON_PADDING
  1554. if [[ $POWERLEVEL9K_MODE == compatible ]]; then
  1555. sub STATUS_ERROR_VISUAL_IDENTIFIER_EXPANSION "'х'"
  1556. sub STATUS_ERROR_SIGNAL_VISUAL_IDENTIFIER_EXPANSION "'х'"
  1557. sub STATUS_ERROR_PIPE_VISUAL_IDENTIFIER_EXPANSION "'х'"
  1558. fi
  1559. if [[ $POWERLEVEL9K_MODE == (compatible|powerline) ]]; then
  1560. uncomment 'typeset -g POWERLEVEL9K_LOCK_ICON'
  1561. sub LOCK_ICON "'∅'"
  1562. uncomment 'typeset -g POWERLEVEL9K_NORDVPN_VISUAL_IDENTIFIER_EXPANSION'
  1563. sub NORDVPN_VISUAL_IDENTIFIER_EXPANSION "'nord'"
  1564. uncomment 'typeset -g POWERLEVEL9K_RANGER_VISUAL_IDENTIFIER_EXPANSION'
  1565. sub RANGER_VISUAL_IDENTIFIER_EXPANSION "'▲'"
  1566. uncomment 'typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_VISUAL_IDENTIFIER_EXPANSION'
  1567. sub KUBECONTEXT_DEFAULT_VISUAL_IDENTIFIER_EXPANSION "'○'"
  1568. uncomment 'typeset -g POWERLEVEL9K_AZURE_VISUAL_IDENTIFIER_EXPANSION'
  1569. sub AZURE_VISUAL_IDENTIFIER_EXPANSION "'az'"
  1570. uncomment 'typeset -g POWERLEVEL9K_AWS_EB_ENV_VISUAL_IDENTIFIER_EXPANSION'
  1571. sub AWS_EB_ENV_VISUAL_IDENTIFIER_EXPANSION "'eb'"
  1572. uncomment 'typeset -g POWERLEVEL9K_BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION'
  1573. sub BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION "'≡'"
  1574. fi
  1575. if [[ $POWERLEVEL9K_MODE == (awesome-patched|awesome-fontconfig) && $cap_python == 0 ]]; then
  1576. uncomment 'typeset -g POWERLEVEL9K_VIRTUALENV_VISUAL_IDENTIFIER_EXPANSION'
  1577. uncomment 'typeset -g POWERLEVEL9K_ANACONDA_VISUAL_IDENTIFIER_EXPANSION'
  1578. uncomment 'typeset -g POWERLEVEL9K_PYENV_VISUAL_IDENTIFIER_EXPANSION'
  1579. uncomment 'typeset -g POWERLEVEL9K_PYTHON_ICON'
  1580. sub VIRTUALENV_VISUAL_IDENTIFIER_EXPANSION "'🐍'"
  1581. sub ANACONDA_VISUAL_IDENTIFIER_EXPANSION "'🐍'"
  1582. sub PYENV_VISUAL_IDENTIFIER_EXPANSION "'🐍'"
  1583. sub PYTHON_ICON "'🐍'"
  1584. fi
  1585. if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then
  1586. sub BATTERY_STAGES "'\uf58d\uf579\uf57a\uf57b\uf57c\uf57d\uf57e\uf57f\uf580\uf581\uf578'"
  1587. fi
  1588. if [[ $style == (classic|rainbow) ]]; then
  1589. if [[ $style == classic ]]; then
  1590. sub BACKGROUND $bg_color[$color]
  1591. sub LEFT_SUBSEGMENT_SEPARATOR "'%$sep_color[$color]F$left_subsep'"
  1592. sub RIGHT_SUBSEGMENT_SEPARATOR "'%$sep_color[$color]F$right_subsep'"
  1593. sub VCS_LOADING_FOREGROUND $sep_color[$color]
  1594. rep '%248F' "%$prefix_color[$color]F"
  1595. else
  1596. sub LEFT_SUBSEGMENT_SEPARATOR "'$left_subsep'"
  1597. sub RIGHT_SUBSEGMENT_SEPARATOR "'$right_subsep'"
  1598. fi
  1599. sub RULER_FOREGROUND $frame_color[$color]
  1600. sub MULTILINE_FIRST_PROMPT_GAP_FOREGROUND $frame_color[$color]
  1601. sub MULTILINE_FIRST_PROMPT_PREFIX "'%$frame_color[$color]F╭─'"
  1602. sub MULTILINE_NEWLINE_PROMPT_PREFIX "'%$frame_color[$color]F├─'"
  1603. sub MULTILINE_LAST_PROMPT_PREFIX "'%$frame_color[$color]F╰─'"
  1604. sub MULTILINE_FIRST_PROMPT_SUFFIX "'%$frame_color[$color]F─╮'"
  1605. sub MULTILINE_NEWLINE_PROMPT_SUFFIX "'%$frame_color[$color]F─┤'"
  1606. sub MULTILINE_LAST_PROMPT_SUFFIX "'%$frame_color[$color]F─╯'"
  1607. sub LEFT_SEGMENT_SEPARATOR "'$left_sep'"
  1608. sub RIGHT_SEGMENT_SEPARATOR "'$right_sep'"
  1609. sub LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL "'$left_tail'"
  1610. sub LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL "'$left_head'"
  1611. sub RIGHT_PROMPT_FIRST_SEGMENT_START_SYMBOL "'$right_head'"
  1612. sub RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL "'$right_tail'"
  1613. fi
  1614. if [[ -n ${(j::)extra_icons} ]]; then
  1615. local branch_icon=${icons[VCS_BRANCH_ICON]// }
  1616. sub VCS_BRANCH_ICON "'$branch_icon '"
  1617. uncomment os_icon
  1618. else
  1619. uncomment 'typeset -g POWERLEVEL9K_DIR_CLASSES'
  1620. uncomment 'typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_EXPANSION'
  1621. uncomment 'typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_VISUAL_IDENTIFIER_EXPANSION'
  1622. uncomment 'typeset -g POWERLEVEL9K_TIME_VISUAL_IDENTIFIER_EXPANSION'
  1623. sub VCS_VISUAL_IDENTIFIER_EXPANSION ''
  1624. sub COMMAND_EXECUTION_TIME_VISUAL_IDENTIFIER_EXPANSION ''
  1625. sub TIME_VISUAL_IDENTIFIER_EXPANSION ''
  1626. fi
  1627. if [[ -n ${(j::)prefixes} ]]; then
  1628. uncomment 'typeset -g POWERLEVEL9K_VCS_PREFIX'
  1629. uncomment 'typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_PREFIX'
  1630. uncomment 'typeset -g POWERLEVEL9K_CONTEXT_PREFIX'
  1631. uncomment 'typeset -g POWERLEVEL9K_KUBECONTEXT_PREFIX'
  1632. uncomment 'typeset -g POWERLEVEL9K_TIME_PREFIX'
  1633. uncomment 'typeset -g POWERLEVEL9K_TOOLBOX_PREFIX'
  1634. if [[ $style == (lean|classic) ]]; then
  1635. [[ $style == classic ]] && local fg="%$prefix_color[$color]F" || local fg="%f"
  1636. sub VCS_PREFIX "'${fg}on '"
  1637. sub COMMAND_EXECUTION_TIME_PREFIX "'${fg}took '"
  1638. sub CONTEXT_PREFIX "'${fg}with '"
  1639. sub KUBECONTEXT_PREFIX "'${fg}at '"
  1640. sub TIME_PREFIX "'${fg}at '"
  1641. sub TOOLBOX_PREFIX "'${fg}in '"
  1642. fi
  1643. fi
  1644. sub MULTILINE_FIRST_PROMPT_GAP_CHAR "'$gap_char'"
  1645. if [[ $style == (classic|rainbow) && $num_lines == 2 ]]; then
  1646. if (( ! right_frame )); then
  1647. sub MULTILINE_FIRST_PROMPT_SUFFIX ''
  1648. sub MULTILINE_NEWLINE_PROMPT_SUFFIX ''
  1649. sub MULTILINE_LAST_PROMPT_SUFFIX ''
  1650. fi
  1651. if (( ! left_frame )); then
  1652. sub MULTILINE_FIRST_PROMPT_PREFIX ''
  1653. sub MULTILINE_NEWLINE_PROMPT_PREFIX ''
  1654. sub MULTILINE_LAST_PROMPT_PREFIX ''
  1655. sub STATUS_OK false
  1656. sub STATUS_ERROR false
  1657. fi
  1658. fi
  1659. if [[ $style == lean* ]]; then
  1660. sub RULER_FOREGROUND $frame_color[$color]
  1661. sub MULTILINE_FIRST_PROMPT_GAP_FOREGROUND $frame_color[$color]
  1662. if (( right_frame )); then
  1663. sub MULTILINE_FIRST_PROMPT_SUFFIX "'%$frame_color[$color]F─╮'"
  1664. sub MULTILINE_NEWLINE_PROMPT_SUFFIX "'%$frame_color[$color]F─┤'"
  1665. sub MULTILINE_LAST_PROMPT_SUFFIX "'%$frame_color[$color]F─╯'"
  1666. sub RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL "' '"
  1667. fi
  1668. if (( left_frame )); then
  1669. sub MULTILINE_FIRST_PROMPT_PREFIX "'%$frame_color[$color]F╭─'"
  1670. sub MULTILINE_NEWLINE_PROMPT_PREFIX "'%$frame_color[$color]F├─'"
  1671. sub MULTILINE_LAST_PROMPT_PREFIX "'%$frame_color[$color]F╰─'"
  1672. sub LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL "' '"
  1673. fi
  1674. fi
  1675. if [[ $style == (classic|rainbow) ]]; then
  1676. if (( num_lines == 2 && ! left_frame )); then
  1677. uncomment prompt_char
  1678. else
  1679. uncomment vi_mode
  1680. fi
  1681. fi
  1682. if [[ $POWERLEVEL9K_MODE == ascii ]]; then
  1683. sub 'STATUS_OK_VISUAL_IDENTIFIER_EXPANSION' "'ok'"
  1684. sub 'STATUS_OK_PIPE_VISUAL_IDENTIFIER_EXPANSION' "'ok'"
  1685. sub 'STATUS_ERROR_VISUAL_IDENTIFIER_EXPANSION' "'err'"
  1686. sub 'STATUS_ERROR_SIGNAL_VISUAL_IDENTIFIER_EXPANSION' ""
  1687. sub 'STATUS_ERROR_PIPE_VISUAL_IDENTIFIER_EXPANSION' "'err'"
  1688. sub 'BATTERY_STAGES' "('battery')"
  1689. sub 'PROMPT_CHAR_{OK,ERROR}_VIINS_CONTENT_EXPANSION' "'>'"
  1690. sub 'PROMPT_CHAR_{OK,ERROR}_VICMD_CONTENT_EXPANSION' "'<'"
  1691. sub 'PROMPT_CHAR_{OK,ERROR}_VIVIS_CONTENT_EXPANSION' "'V'"
  1692. sub 'PROMPT_CHAR_{OK,ERROR}_VIOWR_CONTENT_EXPANSION' "'^'"
  1693. rep "-i '⭐'" "-i '*'"
  1694. rep '…' '..'
  1695. rep '⇣' '<'
  1696. rep '⇡' '>'
  1697. rep '⇠' '<-'
  1698. rep '⇢' '->'
  1699. rep '─' '-'
  1700. fi
  1701. fi
  1702. if (( $+pure_use_rprompt )); then
  1703. local segment
  1704. for segment in command_execution_time virtualenv context; do
  1705. rep " $segment" " tmp_$segment"
  1706. uncomment $segment
  1707. rep " tmp_$segment " " # $segment"
  1708. done
  1709. fi
  1710. if [[ -n $time ]]; then
  1711. uncomment time
  1712. if [[ $time == $time_12h ]]; then
  1713. sub TIME_FORMAT "'%D{%I:%M:%S %p}'"
  1714. fi
  1715. fi
  1716. if (( num_lines == 1 )); then
  1717. local -a tmp
  1718. local line
  1719. for line in "$lines[@]"; do
  1720. [[ $line == (' newline'*|*'===[ Line #'*) ]] || tmp+=$line
  1721. done
  1722. lines=("$tmp[@]")
  1723. fi
  1724. (( empty_line )) && sub PROMPT_ADD_NEWLINE true || sub PROMPT_ADD_NEWLINE false
  1725. sub INSTANT_PROMPT $instant_prompt
  1726. (( transient_prompt )) && sub TRANSIENT_PROMPT always
  1727. local header=${(%):-"# Generated by Powerlevel10k configuration wizard on %D{%Y-%m-%d at %H:%M %Z}."}$'\n'
  1728. header+="# Based on romkatv/powerlevel10k/config/p10k-${style//_/-}.zsh"
  1729. if [[ $commands[sum] == ('/bin'|'/usr/bin'|'/usr/local/bin')'/sum' ]]; then
  1730. local -a sum
  1731. if sum=($(sum <<<${base//$'\r\n'/$'\n'} 2>/dev/null)) && (( $#sum == 2 )); then
  1732. header+=", checksum $sum[1]"
  1733. fi
  1734. fi
  1735. header+=$'.\n'
  1736. local line="# Wizard options: $options[1]"
  1737. local opt
  1738. for opt in $options[2,-1]; do
  1739. if (( $#line + $#opt > 85 )); then
  1740. header+=$line
  1741. header+=$',\n'
  1742. line="# $opt"
  1743. else
  1744. line+=", $opt"
  1745. fi
  1746. done
  1747. header+=$line
  1748. header+=$'.\n# Type `p10k configure` to generate another config.\n#'
  1749. command mkdir -p -- ${__p9k_cfg_path:h} || return
  1750. if [[ -e $__p9k_cfg_path ]]; then
  1751. unlink $__p9k_cfg_path || return
  1752. fi
  1753. print -lr -- "$header" "$lines[@]" >$__p9k_cfg_path
  1754. }
  1755. function change_zshrc() {
  1756. (( write_zshrc )) || return 0
  1757. local tmp=$__p9k_zshrc.${(%):-%n}.tmp.$$
  1758. [[ ! -e $__p9k_zshrc ]] || cp -p $__p9k_zshrc $tmp || return
  1759. {
  1760. local -i writable=1
  1761. if [[ -e $tmp && ! -w $tmp ]]; then
  1762. chmod u+w -- $tmp || return
  1763. writable=0
  1764. fi
  1765. print -n >$tmp || return
  1766. if (( !zshrc_has_instant_prompt )); then
  1767. >>$tmp print -r -- "# Enable Powerlevel10k instant prompt. Should stay close to the top of ${(%)__p9k_zshrc_u}.
  1768. # Initialization code that may require console input (password prompts, [y/n]
  1769. # confirmations, etc.) must go above this block; everything else may go below.
  1770. if [[ -r \"\${XDG_CACHE_HOME:-\$HOME/.cache}/p10k-instant-prompt-\${(%):-%n}.zsh\" ]]; then
  1771. source \"\${XDG_CACHE_HOME:-\$HOME/.cache}/p10k-instant-prompt-\${(%):-%n}.zsh\"
  1772. fi" || return
  1773. fi
  1774. if [[ -n $zshrc_content ]]; then
  1775. (( zshrc_has_instant_prompt )) || print >>$tmp || return
  1776. >>$tmp print -r -- $zshrc_content || return
  1777. fi
  1778. if (( !zshrc_has_cfg )); then
  1779. >>$tmp print -r -- "
  1780. # To customize prompt, run \`p10k configure\` or edit ${(%)__p9k_cfg_path_u}.
  1781. [[ ! -f ${(%)__p9k_cfg_path_u} ]] || source ${(%)__p9k_cfg_path_u}" || return
  1782. fi
  1783. (( writable )) || chmod u-w -- $tmp || return
  1784. command mv -f -- $tmp $__p9k_zshrc || return
  1785. } always {
  1786. zf_rm -f -- $tmp
  1787. }
  1788. if [[ -n $zshrc_backup_u ]]; then
  1789. print -rP ""
  1790. flowing +c See "%B${__p9k_zshrc_u//\\/\\\\}%b" changes:
  1791. print -rP "
  1792. %2Fdiff%f %B$zshrc_backup_u%b %B$__p9k_zshrc_u%b"
  1793. fi
  1794. return 0
  1795. }
  1796. function check_zshrc_integration() {
  1797. typeset -g zshrc_content=
  1798. typeset -gi zshrc_has_cfg=0 zshrc_has_instant_prompt=0
  1799. [[ -e $__p9k_zshrc ]] || return 0
  1800. zshrc_content="$(<$__p9k_zshrc)" || return
  1801. local lines=(${(f)zshrc_content})
  1802. local f0=$__p9k_cfg_path_o
  1803. local f1=${(q)f0}
  1804. local f2=${(q-)f0}
  1805. local f3=${(qq)f0}
  1806. local f4=${(qqq)f0}
  1807. local g1=${${(q)__p9k_cfg_path_o}/#(#b)${(q)HOME}\//'~/'}
  1808. local h0='${ZDOTDIR:-~}/.p10k.zsh'
  1809. local h1='${ZDOTDIR:-$HOME}/.p10k.zsh'
  1810. local h2='"${ZDOTDIR:-$HOME}/.p10k.zsh"'
  1811. local h3='"${ZDOTDIR:-$HOME}"/.p10k.zsh'
  1812. local h4='${ZDOTDIR}/.p10k.zsh'
  1813. local h5='"${ZDOTDIR}/.p10k.zsh"'
  1814. local h6='"${ZDOTDIR}"/.p10k.zsh'
  1815. local h7='$ZDOTDIR/.p10k.zsh'
  1816. local h8='"$ZDOTDIR/.p10k.zsh"'
  1817. local h9='"$ZDOTDIR"/.p10k.zsh'
  1818. local h10='$POWERLEVEL9K_CONFIG_FILE'
  1819. local h11='"$POWERLEVEL9K_CONFIG_FILE"'
  1820. if [[ -n ${(@M)lines:#(#b)[^#]#([^[:IDENT:]]|)source[[:space:]]##($f1|$f2|$f3|$f4|$g1|$h0|$h1|$h2|$h3|$h4|$h5|$h6|$h7|$h8|$h9|$h10|$h11)(|[[:space:]]*|'#'*)} ]]; then
  1821. zshrc_has_cfg=1
  1822. fi
  1823. local pre='${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh'
  1824. if [[ -n ${(@M)lines:#(#b)[^#]#([^[:IDENT:]]|)source[[:space:]]##($pre|\"$pre\")(|[[:space:]]*|'#'*)} ]]; then
  1825. zshrc_has_instant_prompt=1
  1826. fi
  1827. return 0
  1828. }
  1829. () {
  1830. (( force )) && return
  1831. _p9k_can_configure -q || return 0
  1832. local zshrc_content zshrc_has_cfg zshrc_has_instant_prompt
  1833. check_zshrc_integration 2>/dev/null || return 0
  1834. (( zshrc_has_cfg )) || return 0
  1835. [[ -s $__p9k_cfg_path ]] || return 0
  1836. print -P ""
  1837. flowing \
  1838. Powerlevel10k configuration file "($__p9k_cfg_path_u)" was not sourced. This \
  1839. might have been caused by errors in zsh startup files, most likely in \
  1840. $__p9k_zshrc_u. See above for any indication of such errors and fix them. If \
  1841. there are no errors, try running Powerlevel10k configuration wizard:
  1842. print -P ''
  1843. print -P ' %2Fp10k%f %Bconfigure%b'
  1844. print -P ''
  1845. flowing \
  1846. If you do nothing, you will see this message again when you start zsh. You can \
  1847. suppress it by defining %BPOWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true%b in \
  1848. $__p9k_zshrc_u.
  1849. print -P ''
  1850. return 1
  1851. } || return
  1852. if (( $+terminfo[smcup] && $+terminfo[rmcup] )) && echoti smcup 2>/dev/null; then
  1853. function restore_screen() {
  1854. echoti rmcup 2>/dev/null
  1855. function restore_screen() {}
  1856. }
  1857. else
  1858. function restore_screen() {}
  1859. fi
  1860. { # always
  1861. if (( force )); then
  1862. _p9k_can_configure || return
  1863. else
  1864. _p9k_can_configure -q || return
  1865. fi
  1866. zmodload zsh/terminfo || return
  1867. autoload -Uz is-at-least || return
  1868. if is-at-least 5.7.1 && [[ $COLORTERM == (24bit|truecolor) ]]; then
  1869. local -ir has_truecolor=1
  1870. else
  1871. local -ir has_truecolor=0
  1872. fi
  1873. stty -echo 2>/dev/null
  1874. while true; do
  1875. local instant_prompt=verbose zshrc_content= zshrc_backup= zshrc_backup_u=
  1876. local -i zshrc_has_cfg=0 zshrc_has_instant_prompt=0 write_zshrc=0
  1877. local POWERLEVEL9K_MODE= POWERLEVEL9K_ICON_PADDING=moderate style= config_backup= config_backup_u=
  1878. local gap_char=' ' prompt_char='❯' down_triangle='\uE0BC' up_triangle='\uE0BA' slanted_bar='\u2571'
  1879. local left_subsep= right_subsep= left_tail= right_tail= left_head= right_head= time=
  1880. local -i num_lines=2 empty_line=0 color=2 left_frame=1 right_frame=1 transient_prompt=0
  1881. local -i cap_diamond=0 cap_python=0 cap_debian=0 cap_lock=0 cap_arrow=0
  1882. local -a extra_icons=('' '' '')
  1883. local -a frame_color=(244 242 240 238)
  1884. local -a color_name=(Lightest Light Dark Darkest)
  1885. local -a prefixes=('' '')
  1886. local -a options=()
  1887. if (( has_truecolor )); then
  1888. local -A pure_color=(${(kv)pure_snazzy})
  1889. else
  1890. local -A pure_color=(${(kv)pure_original})
  1891. fi
  1892. unset pure_use_rprompt
  1893. if [[ $TERM != (dumb|linux) && $langinfo[CODESET] == (utf|UTF)(-|)8 ]]; then
  1894. ask_font || continue
  1895. ask_diamond || continue
  1896. if [[ $AWESOME_GLYPHS_LOADED == 1 ]]; then
  1897. POWERLEVEL9K_MODE=awesome-mapped-fontconfig
  1898. else
  1899. ask_lock '\uF023' || continue
  1900. if (( ! cap_lock )); then
  1901. ask_lock '\uE138' "Let's try another one." || continue
  1902. if (( cap_lock )); then
  1903. if (( cap_diamond )); then
  1904. POWERLEVEL9K_MODE=awesome-patched
  1905. ask_python || continue
  1906. else
  1907. POWERLEVEL9K_MODE=flat
  1908. fi
  1909. else
  1910. if (( cap_diamond )); then
  1911. POWERLEVEL9K_MODE=powerline
  1912. else
  1913. ask_arrow || continue
  1914. (( cap_arrow )) && POWERLEVEL9K_MODE=compatible || POWERLEVEL9K_MODE=ascii
  1915. fi
  1916. fi
  1917. elif (( ! cap_diamond )); then
  1918. POWERLEVEL9K_MODE=awesome-fontconfig
  1919. else
  1920. ask_debian || continue
  1921. if (( cap_debian )); then
  1922. POWERLEVEL9K_MODE=nerdfont-complete
  1923. else
  1924. POWERLEVEL9K_MODE=awesome-fontconfig
  1925. ask_python || continue
  1926. fi
  1927. fi
  1928. fi
  1929. else
  1930. POWERLEVEL9K_MODE=ascii
  1931. fi
  1932. if [[ $POWERLEVEL9K_MODE == powerline ]]; then
  1933. options+=powerline
  1934. elif (( cap_diamond )); then
  1935. options+="$POWERLEVEL9K_MODE + powerline"
  1936. else
  1937. options+="$POWERLEVEL9K_MODE"
  1938. fi
  1939. (( cap_python )) && options[-1]+=' + python'
  1940. if (( cap_diamond )); then
  1941. left_sep=$right_triangle
  1942. right_sep=$left_triangle
  1943. left_subsep=$right_angle
  1944. right_subsep=$left_angle
  1945. left_head=$right_triangle
  1946. right_head=$left_triangle
  1947. else
  1948. left_sep=
  1949. right_sep=
  1950. left_head=
  1951. right_head=
  1952. if [[ $POWERLEVEL9K_MODE == ascii ]]; then
  1953. left_subsep='|'
  1954. right_subsep='|'
  1955. prompt_char='>'
  1956. left_frame=0
  1957. right_frame=0
  1958. else
  1959. left_subsep=$vertical_bar
  1960. right_subsep=$vertical_bar
  1961. fi
  1962. fi
  1963. _p9k_init_icons
  1964. ask_icon_padding || continue
  1965. _p9k_init_icons
  1966. ask_style || continue
  1967. ask_charset || continue
  1968. ask_color_scheme || continue
  1969. ask_color || continue
  1970. ask_use_rprompt || continue
  1971. ask_time || continue
  1972. ask_separators || continue
  1973. ask_heads || continue
  1974. ask_tails || continue
  1975. ask_num_lines || continue
  1976. ask_gap_char || continue
  1977. ask_frame || continue
  1978. ask_ornaments_color || continue
  1979. ask_empty_line || continue
  1980. ask_extra_icons || continue
  1981. ask_prefixes || continue
  1982. ask_transient_prompt || continue
  1983. ask_instant_prompt || continue
  1984. ask_config_overwrite || continue
  1985. ask_zshrc_edit || continue
  1986. break
  1987. done
  1988. restore_screen
  1989. if (( !in_z4h_wizard )); then
  1990. print
  1991. flowing +c New config: "%U${__p9k_cfg_path_u//\\/\\\\}%u."
  1992. if [[ -n $config_backup ]]; then
  1993. flowing +c Backup of the old config: "%U${config_backup_u//\\/\\\\}%u."
  1994. fi
  1995. if [[ -n $zshrc_backup ]]; then
  1996. flowing +c Backup of "%U${__p9k_zshrc_u//\\/\\\\}%u:" "%U${zshrc_backup_u//\\/\\\\}%u."
  1997. fi
  1998. fi
  1999. generate_config || return
  2000. change_zshrc || return
  2001. if (( !in_z4h_wizard )); then
  2002. print -rP ""
  2003. flowing +c File feature requests and bug reports at "$(href https://github.com/romkatv/powerlevel10k/issues)"
  2004. print -rP ""
  2005. fi
  2006. success=1
  2007. } always {
  2008. (( success )) || quit
  2009. consume_input
  2010. stty echo 2>/dev/null
  2011. show_cursor
  2012. restore_screen
  2013. }