1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-21 23:01:57 +00:00

be more tolerant towards misconfigured locales; users with non-utf-8 locales will still have broken shells but at least p10k will work

This commit is contained in:
romkatv 2019-08-05 20:23:30 +02:00
parent d8c509f5c9
commit 59e96984a1
5 changed files with 67 additions and 55 deletions

View file

@ -1,19 +1,12 @@
# Config for Powerlevel10k with classic powerline prompt style. Requires a powerline font.
# The color scheme is suitable for dark terminal background.
#
# Once you've installed Powerlevel10k, run these commands to apply classic style.
#
# curl -fsSL -o ~/p10k-classic.zsh https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-classic.zsh
# echo 'source ~/p10k-classic.zsh' >>! ~/.zshrc
#
# To customize your prompt, open ~/p10k-classic.zsh in your favorite text editor, change it and
# restart ZSH. The file is well-documented.
# Config for Powerlevel10k with classic powerline prompt style. Type `p10k configure` to generate
# your own config based on it.
#
# Tip: Looking for a nice color? Here's a one-liner to print colormap.
#
# for i in {0..255}; do print -Pn "%${i}F${(l:3::0:)i}%f " ${${(M)$((i%8)):#7}:+$'\n'}; done
if [[ -o 'aliases' ]]; then
# Temporarily disable aliases.
'builtin' 'unsetopt' 'aliases'
local p9k_classic_restore_aliases=1
else
@ -23,6 +16,7 @@ fi
() {
emulate -L zsh
setopt no_unset
local LC_ALL=C.UTF-8
# Unset all configuration options. This allows you to apply configiguration changes without
# restarting zsh. Edit ~/.p10k.zsh and type `source ~/.p10k.zsh`.
@ -277,6 +271,13 @@ fi
# typeset -g POWERLEVEL9K_DIR_CLASSES=()
#####################################[ vcs: git status ]######################################
# Branch icon. Set this parameter to '\uF126' for the popular Powerline branch icon.
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
# Untracked files icon. It's really a question mark, your font isn't broken.
# Change the value of this parameter to show a different icon.
typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
# Git status: feature:master#tag ⇣42⇡42 *42 merge ~42 +42 !42 ?42.
#
# You can edit the lines below to customize how Git status looks.
@ -285,7 +286,7 @@ fi
# https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh.
local vcs=''
# 'feature' or '@72f5c8a' if not on a branch.
vcs+='${${VCS_STATUS_LOCAL_BRANCH:+%76F${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${VCS_STATUS_LOCAL_BRANCH//\%/%%}}'
vcs+='${${VCS_STATUS_LOCAL_BRANCH:+%76F'${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}'${VCS_STATUS_LOCAL_BRANCH//\%/%%}}'
vcs+=':-%f@%76F${VCS_STATUS_COMMIT[1,8]}}'
# ':master' if the tracking branch name differs from local branch.
vcs+='${${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH}:+%f:%76F${VCS_STATUS_REMOTE_BRANCH//\%/%%}}'
@ -309,17 +310,10 @@ fi
# ?42 if have untracked files. It's really a question mark, your font isn't broken.
# See POWERLEVEL9K_VCS_UNTRACKED_ICON below if you want to use a different icon.
# Remove the next line if you don't want to see untracked files at all.
vcs+='${${VCS_STATUS_NUM_UNTRACKED:#0}:+ %39F${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}${VCS_STATUS_NUM_UNTRACKED}}'
vcs+='${${VCS_STATUS_NUM_UNTRACKED:#0}:+ %39F'${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}'${VCS_STATUS_NUM_UNTRACKED}}'
# If P9K_CONTENT is not empty, leave it unchanged. It's either "loading" or from vcs_info.
vcs="\${P9K_CONTENT:-$vcs}"
# Branch icon. Set this parameter to $'\uF126' for the popular Powerline branch icon.
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
# Untracked files icon. It's really a question mark, your font isn't broken.
# Change the value of this parameter to show a different icon.
typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
# Disable the default Git status formatting.
typeset -g POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING=true
# Install our own Git status formatter.
@ -330,6 +324,8 @@ fi
# Enable counters for staged, unstaged, etc.
typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED,COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=-1
# Icon color.
typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_COLOR=76
# Custom icon.
# typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_EXPANSION='⭐'
# Custom prefix.

View file

@ -1,13 +1,5 @@
# Config for Powerlevel10k with lean prompt style. Doesn't require a custom font but can take
# advantage of it if available. The color scheme is suitable for dark terminal background.
#
# Once you've installed Powerlevel10k, run these commands to apply lean style.
#
# curl -fsSL -o ~/p10k-lean.zsh https://raw.githubusercontent.com/romkatv/powerlevel10k/master/config/p10k-lean.zsh
# echo 'source ~/p10k-lean.zsh' >>! ~/.zshrc
#
# To customize your prompt, open ~/p10k-lean.zsh in your favorite text editor, change it and
# restart ZSH. The file is well-documented.
# Config for Powerlevel10k with classic powerline prompt style. Type `p10k configure` to generate
# your own config based on it.
#
# Tip: Looking for a nice color? Here's a one-liner to print colormap.
#
@ -24,6 +16,7 @@ fi
() {
emulate -L zsh
setopt no_unset
local LC_ALL=C.UTF-8
# Unset all configuration options. This allows you to apply configiguration changes without
# restarting zsh. Edit ~/.p10k.zsh and type `source ~/.p10k.zsh`.
@ -262,6 +255,13 @@ fi
# typeset -g POWERLEVEL9K_DIR_CLASSES=()
#####################################[ vcs: git status ]######################################
# Branch icon. Set this parameter to '\uF126' for the popular Powerline branch icon.
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
# Untracked files icon. It's really a question mark, your font isn't broken.
# Change the value of this parameter to show a different icon.
typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
# Git status: feature:master#tag ⇣42⇡42 *42 merge ~42 +42 !42 ?42.
#
# You can edit the lines below to customize how Git status looks.
@ -270,7 +270,7 @@ fi
# https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh.
local vcs=''
# 'feature' or '@72f5c8a' if not on a branch.
vcs+='${${VCS_STATUS_LOCAL_BRANCH:+%76F${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${VCS_STATUS_LOCAL_BRANCH//\%/%%}}'
vcs+='${${VCS_STATUS_LOCAL_BRANCH:+%76F'${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}'${VCS_STATUS_LOCAL_BRANCH//\%/%%}}'
vcs+=':-%f@%76F${VCS_STATUS_COMMIT[1,8]}}'
# ':master' if the tracking branch name differs from local branch.
vcs+='${${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH}:+%f:%76F${VCS_STATUS_REMOTE_BRANCH//\%/%%}}'
@ -294,17 +294,10 @@ fi
# ?42 if have untracked files. It's really a question mark, your font isn't broken.
# See POWERLEVEL9K_VCS_UNTRACKED_ICON below if you want to use a different icon.
# Remove the next line if you don't want to see untracked files at all.
vcs+='${${VCS_STATUS_NUM_UNTRACKED:#0}:+ %39F${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}${VCS_STATUS_NUM_UNTRACKED}}'
vcs+='${${VCS_STATUS_NUM_UNTRACKED:#0}:+ %39F'${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}'${VCS_STATUS_NUM_UNTRACKED}}'
# If P9K_CONTENT is not empty, leave it unchanged. It's either "loading" or from vcs_info.
vcs="\${P9K_CONTENT:-$vcs}"
# Branch icon. Set this parameter to $'\uF126' for the popular Powerline branch icon.
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
# Untracked files icon. It's really a question mark, your font isn't broken.
# Change the value of this parameter to show a different icon.
typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
# Disable the default Git status formatting.
typeset -g POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING=true
# Install our own Git status formatter.
@ -315,6 +308,8 @@ fi
# Enable counters for staged, unstaged, etc.
typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED,COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=-1
# Icon color.
typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_COLOR=76
# Custom icon.
# typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_EXPANSION='⭐'
# Custom prefix.

View file

@ -11,36 +11,48 @@ typeset -gr __p9k_root_dir_u=${${${(q-)__p9k_root_dir}/#(#b)$HOME(|\/*)/'~'$matc
function _p9k_can_configure() {
emulate -L zsh
setopt err_return extended_glob no_prompt_{bang,subst} prompt_{cr,percent,sp}
setopt extended_glob no_prompt_{bang,subst} prompt_{cr,percent,sp}
[[ $1 == '-q' ]] && local -i q=1 || local -i q=0
function $0_error() {
(( q )) || print -rP "%1F[ERROR]%f %Bp10k configure%b: $1" >&2
return 1
}
{
[[ -t 0 && -t 1 ]] || $0_error "no TTY"
[[ -o multibyte ]] || $0_error "multibyte option is not set"
[[ "${#$(print '\u276F' 2>/dev/null)}" == 1 ]] || $0_error "shell doesn't support unicode"
[[ -e $__p9k_zd ]] || $0_error "$__p9k_zd_u does not exist"
[[ -d $__p9k_zd ]] || $0_error "$__p9k_zd_u is not a directory"
[[ -w $__p9k_zd ]] || $0_error "$__p9k_zd_u is not writable"
[[ ! -d $__p9k_cfg_path ]] || $0_error "$__p9k_cfg_path_u is a directory"
[[ ! -d $__p9k_zshrc ]] || $0_error "$__p9k_zshrc_u is a directory"
[[ -t 0 && -t 1 ]] || { $0_error "no TTY"; return 1 }
[[ -o multibyte ]] || { $0_error "multibyte option is not set"; return 1 }
[[ -e $__p9k_zd ]] || { $0_error "$__p9k_zd_u does not exist"; return 1 }
[[ -d $__p9k_zd ]] || { $0_error "$__p9k_zd_u is not a directory"; return 1 }
[[ -w $__p9k_zd ]] || { $0_error "$__p9k_zd_u is not writable"; return 1 }
[[ ! -d $__p9k_cfg_path ]] || { $0_error "$__p9k_cfg_path_u is a directory"; return 1 }
[[ ! -d $__p9k_zshrc ]] || { $0_error "$__p9k_zshrc_u is a directory"; return 1 }
[[ ! -e $__p9k_cfg_path || -f $__p9k_cfg_path || -h $__p9k_cfg_path ]] ||
[[ ! -e $__p9k_cfg_path || -f $__p9k_cfg_path || -h $__p9k_cfg_path ]] || {
$0_error "$__p9k_cfg_path_u is a special file"
[[ -r $__p9k_root_dir/config/p10k-lean.zsh ]] ||
return 1
}
[[ -r $__p9k_root_dir/config/p10k-lean.zsh ]] || {
$0_error "cannot read $__p9k_root_dir_u/config/p10k-lean.zsh"
[[ -r $__p9k_root_dir/config/p10k-classic.zsh ]] ||
return 1
}
[[ -r $__p9k_root_dir/config/p10k-classic.zsh ]] || {
$0_error "cannot read $__p9k_root_dir_u/config/p10k-classic.zsh"
[[ ! -e $__p9k_zshrc || -f $__p9k_zshrc || -h $__p9k_zshrc ]] ||
return 1
}
[[ ! -e $__p9k_zshrc || -f $__p9k_zshrc || -h $__p9k_zshrc ]] || {
$0_error "$__p9k_zshrc_u a special file"
[[ ! -e $__p9k_zshrc || -r $__p9k_zshrc ]] ||
return 1
}
[[ ! -e $__p9k_zshrc || -r $__p9k_zshrc ]] || {
$0_error "$__p9k_zshrc_u is not readable"
[[ ! -e $__p9k_zshrc || -w $__p9k_zshrc ]] ||
return 1
}
[[ ! -e $__p9k_zshrc || -w $__p9k_zshrc ]] || {
$0_error "$__p9k_zshrc_u is not writable"
(( LINES >= __p9k_wizard_lines && COLUMNS >= __p9k_wizard_columns )) ||
return 1
}
(( LINES >= __p9k_wizard_lines && COLUMNS >= __p9k_wizard_columns )) || {
$0_error "terminal size too small; must be at least $__p9k_wizard_columns x $__p9k_wizard_lines"
return 1
}
} always {
unfunction $0_error
}

View file

@ -147,6 +147,7 @@ function _p9k_declare() {
(( set )) && typeset -g _$2=${(P)2} || typeset -g _$2=$3
;;
-e)
local LC_ALL=C.UTF-8
if (( set )); then
local v=${(P)2}
typeset -g _$2=${(g::)v}
@ -329,6 +330,7 @@ _p9k_get_icon() {
if [[ $_p9k_ret == $'\1'* ]]; then
_p9k_ret=${_p9k_ret[2,-1]}
else
local LC_ALL=C.UTF-8
_p9k_ret=${(g::)_p9k_ret}
[[ $_p9k_ret != $'\b'? ]] || _p9k_ret="%{$_p9k_ret%}" # penance for past sins
fi
@ -549,6 +551,7 @@ _p9k_left_prompt_segment() {
p+='${${_p9k_e:#00}:+${${_p9k_t[$_p9k_n]/'$ss'/$_p9k_ss}/'$s'/$_p9k_s}'
local LC_ALL=C.UTF-8
_p9k_param $1 ICON_BEFORE_CONTENT ''
if [[ $_p9k_ret != false ]]; then
_p9k_param $1 PREFIX ''
@ -749,6 +752,7 @@ _p9k_right_prompt_segment() {
p+='${${_p9k_e:#00}:+${_p9k_t[$_p9k_n]/'$w'/$_p9k_w}'
local LC_ALL=C.UTF-8
_p9k_param $1 ICON_BEFORE_CONTENT ''
if [[ $_p9k_ret != true ]]; then
_p9k_param $1 PREFIX ''
@ -1087,6 +1091,7 @@ prompt_context() {
if [[ -z $content ]]; then
local var=POWERLEVEL9K_CONTEXT_${state}_TEMPLATE
if (( $+parameters[$var] )); then
local LC_ALL=C.UTF-8
content=${(P)var}
content=${(g::)content}
else
@ -3508,6 +3513,7 @@ _p9k_init_params() {
if [[ $parameters[POWERLEVEL9K_BATTERY_STAGES] == scalar ]]; then
_p9k_declare -e POWERLEVEL9K_BATTERY_STAGES
else
local LC_ALL=C.UTF-8
_p9k_declare -a POWERLEVEL9K_BATTERY_STAGES --
_POWERLEVEL9K_BATTERY_STAGES=("${(@g::)_POWERLEVEL9K_BATTERY_STAGES}")
fi
@ -3765,6 +3771,7 @@ _p9k_build_gap_post() {
}
_p9k_init_lines() {
local LC_ALL=C.UTF-8
local -a left_segments=($_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS)
local -a right_segments=($_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS)
@ -4167,6 +4174,7 @@ _p9k_init() {
if _p9k_segment_in_use dir; then
if (( $+_POWERLEVEL9K_DIR_CLASSES )); then
local LC_ALL=C.UTF-8
local -i i=3
for ((; i <= $#_POWERLEVEL9K_DIR_CLASSES; i+=3)); do
_POWERLEVEL9K_DIR_CLASSES[i]=${(g::)_POWERLEVEL9K_DIR_CLASSES[i]}

View file

@ -5,6 +5,7 @@ setopt noaliases
() {
setopt extended_glob no_prompt_{bang,subst} prompt_{cr,percent,sp}
local LC_ALL=C.UTF-8
typeset -g __p9k_root_dir
typeset -gi force=0