configure.zsh 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Fewer than 47 columns will probably work. Haven't tried it.
  2. typeset -gr __p9k_wizard_columns=47
  3. # The bottleneck is ask_tails with nerd fonts. Everything else works fine with 12 lines.
  4. typeset -gr __p9k_wizard_lines=14
  5. typeset -gr __p9k_zd=${ZDOTDIR:-$HOME}
  6. typeset -gr __p9k_zd_u=${${${(q)__p9k_zd}/#(#b)${(q)HOME}(|\/*)/'~'$match[1]}//\%/%%}
  7. typeset -gr __p9k_zshrc=${${:-$__p9k_zd/.zshrc}:A}
  8. typeset -gr __p9k_zshrc_u=$__p9k_zd_u/.zshrc
  9. typeset -gr __p9k_root_dir_u=${${${(q)__p9k_root_dir}/#(#b)${(q)HOME}(|\/*)/'~'$match[1]}//\%/%%}
  10. function _p9k_can_configure() {
  11. [[ $1 == '-q' ]] && local -i q=1 || local -i q=0
  12. function $0_error() {
  13. (( q )) || print -rP "%1F[ERROR]%f %Bp10k configure%b: $1" >&2
  14. }
  15. typeset -g __p9k_cfg_path_o=${POWERLEVEL9K_CONFIG_FILE:=${ZDOTDIR:-~}/.p10k.zsh}
  16. typeset -g __p9k_cfg_basename=${__p9k_cfg_path_o:t}
  17. typeset -g __p9k_cfg_path=${__p9k_cfg_path_o:A}
  18. typeset -g __p9k_cfg_path_u=${${${(q)__p9k_cfg_path_o}/#(#b)${(q)HOME}(|\/*)/'~'$match[1]}//\%/%%}
  19. {
  20. [[ -e $__p9k_zd ]] || { $0_error "$__p9k_zd_u does not exist"; return 1 }
  21. [[ -d $__p9k_zd ]] || { $0_error "$__p9k_zd_u is not a directory"; return 1 }
  22. [[ ! -d $__p9k_cfg_path ]] || { $0_error "$__p9k_cfg_path_u is a directory"; return 1 }
  23. [[ ! -d $__p9k_zshrc ]] || { $0_error "$__p9k_zshrc_u is a directory"; return 1 }
  24. local dir=${__p9k_cfg_path:h}
  25. while [[ ! -e $dir && $dir != ${dir:h} ]]; do dir=${dir:h}; done
  26. if [[ ! -d $dir ]]; then
  27. $0_error "cannot create $__p9k_cfg_path_u because ${dir//\%/%%} is not a directory"
  28. return 1
  29. fi
  30. if [[ ! -w $dir ]]; then
  31. $0_error "cannot create $__p9k_cfg_path_u because ${dir//\%/%%} is readonly"
  32. return 1
  33. fi
  34. [[ ! -e $__p9k_cfg_path || -f $__p9k_cfg_path || -h $__p9k_cfg_path ]] || {
  35. $0_error "$__p9k_cfg_path_u is a special file"
  36. return 1
  37. }
  38. [[ ! -e $__p9k_zshrc || -f $__p9k_zshrc || -h $__p9k_zshrc ]] || {
  39. $0_error "$__p9k_zshrc_u a special file"
  40. return 1
  41. }
  42. [[ ! -e $__p9k_zshrc || -r $__p9k_zshrc ]] || {
  43. $0_error "$__p9k_zshrc_u is not readable"
  44. return 1
  45. }
  46. local style
  47. for style in lean lean-8colors classic rainbow pure; do
  48. [[ -r $__p9k_root_dir/config/p10k-$style.zsh ]] || {
  49. $0_error "$__p9k_root_dir_u/config/p10k-$style.zsh is not readable"
  50. return 1
  51. }
  52. done
  53. (( LINES >= __p9k_wizard_lines && COLUMNS >= __p9k_wizard_columns )) || {
  54. $0_error "terminal size too small; must be at least $__p9k_wizard_columns columns by $__p9k_wizard_lines lines"
  55. return 1
  56. }
  57. [[ -t 0 && -t 1 ]] || {
  58. $0_error "no TTY"
  59. return 2
  60. }
  61. return 0
  62. } always {
  63. unfunction $0_error
  64. }
  65. }
  66. function p9k_configure() {
  67. eval "$__p9k_intro"
  68. _p9k_can_configure || return
  69. (
  70. set -- -f
  71. builtin source $__p9k_root_dir/internal/wizard.zsh
  72. )
  73. local ret=$?
  74. case $ret in
  75. 0) builtin source $__p9k_cfg_path; _p9k__force_must_init=1;;
  76. 69) return 0;;
  77. *) return $ret;;
  78. esac
  79. }