Обновления конфигов
This commit is contained in:
parent
49e5fa5710
commit
cefce84f5e
91 changed files with 33559 additions and 8 deletions
84
zsh/theme/internal/configure.zsh
Normal file
84
zsh/theme/internal/configure.zsh
Normal file
|
@ -0,0 +1,84 @@
|
|||
# Fewer than 47 columns will probably work. Haven't tried it.
|
||||
typeset -gr __p9k_wizard_columns=47
|
||||
# The bottleneck is ask_tails with nerd fonts. Everything else works fine with 12 lines.
|
||||
typeset -gr __p9k_wizard_lines=14
|
||||
typeset -gr __p9k_zd=${ZDOTDIR:-$HOME}
|
||||
typeset -gr __p9k_zd_u=${${${(q)__p9k_zd}/#(#b)${(q)HOME}(|\/*)/'~'$match[1]}//\%/%%}
|
||||
typeset -gr __p9k_zshrc=${${:-$__p9k_zd/.zshrc}:A}
|
||||
typeset -gr __p9k_zshrc_u=$__p9k_zd_u/.zshrc
|
||||
typeset -gr __p9k_root_dir_u=${${${(q)__p9k_root_dir}/#(#b)${(q)HOME}(|\/*)/'~'$match[1]}//\%/%%}
|
||||
|
||||
function _p9k_can_configure() {
|
||||
[[ $1 == '-q' ]] && local -i q=1 || local -i q=0
|
||||
function $0_error() {
|
||||
(( q )) || print -rP "%1F[ERROR]%f %Bp10k configure%b: $1" >&2
|
||||
}
|
||||
typeset -g __p9k_cfg_path_o=${POWERLEVEL9K_CONFIG_FILE:=${ZDOTDIR:-~}/.p10k.zsh}
|
||||
typeset -g __p9k_cfg_basename=${__p9k_cfg_path_o:t}
|
||||
typeset -g __p9k_cfg_path=${__p9k_cfg_path_o:A}
|
||||
typeset -g __p9k_cfg_path_u=${${${(q)__p9k_cfg_path_o}/#(#b)${(q)HOME}(|\/*)/'~'$match[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 }
|
||||
[[ ! -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 }
|
||||
|
||||
local dir=${__p9k_cfg_path:h}
|
||||
while [[ ! -e $dir && $dir != ${dir:h} ]]; do dir=${dir:h}; done
|
||||
if [[ ! -d $dir ]]; then
|
||||
$0_error "cannot create $__p9k_cfg_path_u because ${dir//\%/%%} is not a directory"
|
||||
return 1
|
||||
fi
|
||||
if [[ ! -w $dir ]]; then
|
||||
$0_error "cannot create $__p9k_cfg_path_u because ${dir//\%/%%} is readonly"
|
||||
return 1
|
||||
fi
|
||||
|
||||
[[ ! -e $__p9k_cfg_path || -f $__p9k_cfg_path || -h $__p9k_cfg_path ]] || {
|
||||
$0_error "$__p9k_cfg_path_u is a special file"
|
||||
return 1
|
||||
}
|
||||
[[ ! -e $__p9k_zshrc || -f $__p9k_zshrc || -h $__p9k_zshrc ]] || {
|
||||
$0_error "$__p9k_zshrc_u a special file"
|
||||
return 1
|
||||
}
|
||||
[[ ! -e $__p9k_zshrc || -r $__p9k_zshrc ]] || {
|
||||
$0_error "$__p9k_zshrc_u is not readable"
|
||||
return 1
|
||||
}
|
||||
local style
|
||||
for style in lean lean-8colors classic rainbow pure; do
|
||||
[[ -r $__p9k_root_dir/config/p10k-$style.zsh ]] || {
|
||||
$0_error "$__p9k_root_dir_u/config/p10k-$style.zsh is not readable"
|
||||
return 1
|
||||
}
|
||||
done
|
||||
|
||||
(( LINES >= __p9k_wizard_lines && COLUMNS >= __p9k_wizard_columns )) || {
|
||||
$0_error "terminal size too small; must be at least $__p9k_wizard_columns columns by $__p9k_wizard_lines lines"
|
||||
return 1
|
||||
}
|
||||
[[ -t 0 && -t 1 ]] || {
|
||||
$0_error "no TTY"
|
||||
return 2
|
||||
}
|
||||
return 0
|
||||
} always {
|
||||
unfunction $0_error
|
||||
}
|
||||
}
|
||||
|
||||
function p9k_configure() {
|
||||
eval "$__p9k_intro"
|
||||
_p9k_can_configure || return
|
||||
(
|
||||
set -- -f
|
||||
builtin source $__p9k_root_dir/internal/wizard.zsh
|
||||
)
|
||||
local ret=$?
|
||||
case $ret in
|
||||
0) builtin source $__p9k_cfg_path; _p9k__force_must_init=1;;
|
||||
69) return 0;;
|
||||
*) return $ret;;
|
||||
esac
|
||||
}
|
BIN
zsh/theme/internal/configure.zsh.zwc
Normal file
BIN
zsh/theme/internal/configure.zsh.zwc
Normal file
Binary file not shown.
1167
zsh/theme/internal/icons.zsh
Normal file
1167
zsh/theme/internal/icons.zsh
Normal file
File diff suppressed because it is too large
Load diff
BIN
zsh/theme/internal/icons.zsh.zwc
Normal file
BIN
zsh/theme/internal/icons.zsh.zwc
Normal file
Binary file not shown.
197
zsh/theme/internal/notes.md
Normal file
197
zsh/theme/internal/notes.md
Normal file
|
@ -0,0 +1,197 @@
|
|||
battery: use the same technique as in vpn_ip to avoid reset=2.
|
||||
|
||||
---
|
||||
|
||||
implement fake gitstatus api on top of vcs_info (or plain git?) + worker and use it if there is no
|
||||
gitstatus.
|
||||
|
||||
---
|
||||
|
||||
- call vcs_info on worker. the tricky question is what to display while "loading".
|
||||
|
||||
---
|
||||
|
||||
- add _SHOW_SYSTEM to all *env segments.
|
||||
|
||||
---
|
||||
|
||||
- support states in SHOW_ON_COMMAND: POWERLEVEL9K_SEGMENT_STATE_SHOW_ON_COMMAND='...'
|
||||
|
||||
---
|
||||
|
||||
add POWERLEVEL9K_${SEGMENT}_${STATE}_SHOW_IN_DIR='pwd_pattern'; implement the same way as
|
||||
SHOW_ON_UPGLOB. how should it interact with POWERLEVEL9K_${SEGMENT}_DISABLED_DIR_PATTERN?
|
||||
|
||||
---
|
||||
|
||||
add `p10k upglob`; returns 0 on match and sets REPLY to the directory where match was found.
|
||||
|
||||
---
|
||||
|
||||
when directory cannot be shortened any further, start chopping off segments from the left and
|
||||
replacing the chopped off part with `…`. e.g., `…/x/anchor/y/anchor`. the shortest dir
|
||||
representation is thus `…/last` or `…/last` depending on whether the last segment is an anchor.
|
||||
the replacement parameter's value is `…/` (with a slash) to allow for `x/anchor/y/anchor`.
|
||||
|
||||
---
|
||||
|
||||
- add to faq: how do i display an environment variable in prompt? link it from "extensible"
|
||||
|
||||
---
|
||||
|
||||
- add to faq: how do i display an icon in prompt? link it from "extensible"
|
||||
|
||||
---
|
||||
|
||||
- add root_indicator to config templates
|
||||
|
||||
---
|
||||
|
||||
- test chruby and add it to config templates
|
||||
|
||||
---
|
||||
|
||||
- add ssh to config templates
|
||||
|
||||
---
|
||||
|
||||
- add swift version to config templates; see if there is a good pattern for PROJECT_ONLY
|
||||
|
||||
---
|
||||
|
||||
- add swiftenv
|
||||
|
||||
---
|
||||
|
||||
- add faq: how to customize directory shortening? mention POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER,
|
||||
POWERLEVEL9K_DIR_MAX_LENGTH and co., and truncate_to_last.
|
||||
|
||||
---
|
||||
|
||||
fix a bug in zsh: https://github.com/romkatv/powerlevel10k/issues/502. to reproduce:
|
||||
|
||||
```zsh
|
||||
emulate zsh -o prompt_percent -c 'print -P "%F{#ff0000}red%F{green}%B bold green"'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
add `p10k explain` that prints something like this:
|
||||
|
||||
```text
|
||||
segment icons meaning
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
--
|
||||
status ✔ ✘ exit code of the last command
|
||||
```
|
||||
|
||||
implement it the hard way: for every enabled segment go over all its {state,icon} pairs, resolve
|
||||
the icon (if not absolute), apply VISUAL_IDENTIFIER_EXPANSION, remove leading and trailing
|
||||
whitespace and print without formatting (sort of like `print -P | cat`); print segment names in
|
||||
green and icons in bold; battery can have an unlimited number of icons, so `...` would be needed
|
||||
(based on total length of concatenated icons rather than the number of icons); user-defined
|
||||
segments would have "unknown" icons by default (yellow and not bold); can allow them to
|
||||
participate by defining `explainprompt_foo` that populates array `reply` with strings like this:
|
||||
'-s STATE -i LOCK_ICON +r'; the first element must be segment description.
|
||||
|
||||
---
|
||||
|
||||
add `docker_context` prompt segment; similar to `kubecontext`; the data should come from
|
||||
`currentContext` field in `~/.docker/config.json` (according to
|
||||
https://github.com/starship/starship/issues/995); there is also `DOCKER_CONTEXT`; more info:
|
||||
https://docs.docker.com/engine/reference/commandline/context_use; also
|
||||
https://github.com/starship/starship/pull/996.
|
||||
|
||||
---
|
||||
|
||||
support `env`, `ionice` and `strace` precommands in `parser.zsh`.
|
||||
|
||||
---
|
||||
|
||||
Add ruler to configuration wizard. Options: `─`, `·`, `╌`, `┄`, `▁`, `═`.
|
||||
|
||||
---
|
||||
|
||||
Add frame styles to the wizard.
|
||||
|
||||
```text
|
||||
╭─
|
||||
╰─
|
||||
|
||||
┌─
|
||||
└─
|
||||
|
||||
┏━
|
||||
┗━
|
||||
|
||||
╔═
|
||||
╚═
|
||||
|
||||
▛▀
|
||||
▙▄
|
||||
```
|
||||
|
||||
Prompt connection should have matching options.
|
||||
|
||||
---
|
||||
|
||||
Add `POWERLEVEL9K_{LEFT,RIGHT}_SEGMENT_MIRROR_SEPARATOR`. If set, left segments get separated with
|
||||
`POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR` followed by `POWERLEVEL9K_LEFT_SEGMENT_MIRROR_SEPARATOR`.
|
||||
Each is drawn without background. The first with the foreground of left segment, the second with
|
||||
the background of right segment. To insert space in between, embed it in
|
||||
`POWERLEVEL9K_{LEFT,RIGHT}_SEGMENT_MIRROR_SEPARATOR`.
|
||||
`POWERLEVEL9K_{LEFT,RIGHT}_SUBSEGMENT_SEPARATOR` is unused.
|
||||
|
||||
---
|
||||
|
||||
Add *Segment Connection* screen to configuration wizard with options *Fused*, *Touching* and
|
||||
*Disjoint*. The last two differ by the absence/presence of space between `SEGMENT_SEPARATOR` and
|
||||
`SEGMENT_MIRROR_SEPARATOR`.
|
||||
|
||||
*Fused* requires line separator (there is already a screen for it) but the other two options require
|
||||
two filled separators similar to heads and tail. Figure out how to present this choice.
|
||||
|
||||
---
|
||||
|
||||
Optimize auto-wizard check.
|
||||
|
||||
```text
|
||||
time ( repeat 1000 [[ -z "${parameters[(I)POWERLEVEL9K_*~(POWERLEVEL9K_MODE|POWERLEVEL9K_CONFIG_FILE)]}" ]] )
|
||||
user=0.21s system=0.05s cpu=99% total=0.264
|
||||
|
||||
time ( repeat 1000 [[ -z "${parameters[(I)POWERLEVEL9K_*]}" ]] )
|
||||
user=0.17s system=0.00s cpu=99% total=0.175
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Add the equivalent of `P9K_PYTHON_VERSION` to all `*env` segments where it makes sense.
|
||||
|
||||
---
|
||||
|
||||
Define `P9K_ICON` on initialization. Fill it with `$icon`. Duplicate every key that ends in `_ICON`.
|
||||
Respect `POWERLEVEL9K_VCS_STASH_ICON` overrides but not anything with segment name or state.
|
||||
|
||||
Define `POWERLEVEL9K_VCS_*` parameters in config templates for all symbols used in
|
||||
`my_git_formatter`. Add missing entries to `icons`. Use `$P9K_ICON[...]` within `my_git_formatter`.
|
||||
Add a screen to the wizard to choose between clear and circled icons.
|
||||
|
||||
---
|
||||
|
||||
Add a screen to the wizard asking whether to set `POWERLEVEL9K_VCS_DISABLED_WORKDIR_PATTERN='~'`.
|
||||
Show it only if there is `$HOME/.git`. By default this parameter should be commented out.
|
9491
zsh/theme/internal/p10k.zsh
Normal file
9491
zsh/theme/internal/p10k.zsh
Normal file
File diff suppressed because it is too large
Load diff
BIN
zsh/theme/internal/p10k.zsh.zwc
Normal file
BIN
zsh/theme/internal/p10k.zsh.zwc
Normal file
Binary file not shown.
382
zsh/theme/internal/parser.zsh
Normal file
382
zsh/theme/internal/parser.zsh
Normal file
|
@ -0,0 +1,382 @@
|
|||
typeset -grA __p9k_pb_cmd_skip=(
|
||||
'}' 'always' # handled specially
|
||||
'{' ''
|
||||
'{' ''
|
||||
'|' ''
|
||||
'||' ''
|
||||
'&' ''
|
||||
'&&' ''
|
||||
'|&' ''
|
||||
'&!' ''
|
||||
'&|' ''
|
||||
')' ''
|
||||
'(' ''
|
||||
'()' ''
|
||||
'!' ''
|
||||
';' ''
|
||||
'if' ''
|
||||
'fi' ''
|
||||
'elif' ''
|
||||
'else' ''
|
||||
'then' ''
|
||||
'while' ''
|
||||
'until' ''
|
||||
'do' ''
|
||||
'done' ''
|
||||
'esac' ''
|
||||
'end' ''
|
||||
'coproc' ''
|
||||
'nocorrect' ''
|
||||
'noglob' ''
|
||||
'time' ''
|
||||
'[[' '\]\]'
|
||||
'((' '\)\)'
|
||||
'case' '\)|esac'
|
||||
';;' '\)|esac'
|
||||
';&' '\)|esac'
|
||||
';|' '\)|esac'
|
||||
'foreach' '\(*\)'
|
||||
)
|
||||
|
||||
typeset -grA __p9k_pb_precommand=(
|
||||
'-' ''
|
||||
'builtin' ''
|
||||
'command' ''
|
||||
'exec' '-[^a]#[a]'
|
||||
'nohup' ''
|
||||
'setsid' ''
|
||||
'eatmydata' ''
|
||||
'catchsegv' ''
|
||||
'pkexec' '--user'
|
||||
'doas' '-[^aCu]#[acU]'
|
||||
'nice' '-[^n]#[n]|--adjustment'
|
||||
'stdbuf' '-[^ioe]#[ioe]|--(input|output|error)'
|
||||
'sudo' '-[^aghpuUCcrtT]#[aghpuUCcrtT]|--(close-from|group|host|prompt|role|type|other-user|command-timeout|user)'
|
||||
'ssh-agent' '-[^aEPt]#[aEPt]'
|
||||
'tabbed' '-[^gnprtTuU]#[gnprtTuU]'
|
||||
'chronic' ''
|
||||
'ifne' ''
|
||||
)
|
||||
|
||||
typeset -grA __p9k_pb_redirect=(
|
||||
'&>' ''
|
||||
'>' ''
|
||||
'>&' ''
|
||||
'<' ''
|
||||
'<&' ''
|
||||
'<>' ''
|
||||
'&>|' ''
|
||||
'>|' ''
|
||||
'&>>' ''
|
||||
'>>' ''
|
||||
'>>&' ''
|
||||
'&>>|' ''
|
||||
'>>|' ''
|
||||
'<<<' ''
|
||||
)
|
||||
|
||||
typeset -grA __p9k_pb_term=(
|
||||
'|' ''
|
||||
'||' ''
|
||||
';' ''
|
||||
'&' ''
|
||||
'&&' ''
|
||||
'|&' ''
|
||||
'&!' ''
|
||||
'&|' ''
|
||||
';;' ''
|
||||
';&' ''
|
||||
';|' ''
|
||||
'(' ''
|
||||
')' ''
|
||||
'()' '' # handled specially
|
||||
'}' '' # handled specially
|
||||
)
|
||||
|
||||
typeset -grA __p9k_pb_term_skip=(
|
||||
'(' '\)'
|
||||
';;' '\)|esac'
|
||||
';&' '\)|esac'
|
||||
';|' '\)|esac'
|
||||
)
|
||||
|
||||
# Usage: _p9k_parse_buffer <buffer> [token-limit]
|
||||
#
|
||||
# Parses the specified command line buffer and pupulates array P9K_COMMANDS
|
||||
# with commands from it. Terminates early and returns 1 if there are more
|
||||
# tokens than the specified limit.
|
||||
#
|
||||
# Broken:
|
||||
#
|
||||
# ---------------
|
||||
# : $(x)
|
||||
# ---------------
|
||||
# : `x`
|
||||
# ---------------
|
||||
# ${x/}
|
||||
# ---------------
|
||||
# - -- x
|
||||
# ---------------
|
||||
# command -p -p x
|
||||
# ---------------
|
||||
# *
|
||||
# ---------------
|
||||
# x=$y; $x
|
||||
# ---------------
|
||||
# alias x=y; y
|
||||
# ---------------
|
||||
# x <<END
|
||||
# ; END
|
||||
# END
|
||||
# ---------------
|
||||
# Setup:
|
||||
# setopt interactive_comments
|
||||
# alias x='#'
|
||||
# Punchline:
|
||||
# x; y
|
||||
# ---------------
|
||||
#
|
||||
# More brokenness with non-standard options (ignore_braces, ignore_close_braces, etc.).
|
||||
function _p9k_parse_buffer() {
|
||||
[[ ${2:-0} == <-> ]] || return 2
|
||||
|
||||
local rcquotes
|
||||
[[ -o rcquotes ]] && rcquotes=rcquotes
|
||||
|
||||
eval "$__p9k_intro"
|
||||
setopt no_nomatch $rcquotes
|
||||
|
||||
typeset -ga P9K_COMMANDS=()
|
||||
|
||||
local -r id='(<->|[[:alpha:]_][[:IDENT:]]#)'
|
||||
local -r var="\$$id|\${$id}|\"\$$id\"|\"\${$id}\""
|
||||
|
||||
local -i e ic c=${2:-'1 << 62'}
|
||||
local skip n s r state token cmd prev
|
||||
local -a aln alp alf v
|
||||
|
||||
if [[ -o interactive_comments ]]; then
|
||||
ic=1
|
||||
local tokens=(${(Z+C+)1})
|
||||
else
|
||||
local tokens=(${(z)1})
|
||||
fi
|
||||
|
||||
{
|
||||
while (( $#tokens )); do
|
||||
(( e = $#state ))
|
||||
|
||||
while (( $#tokens == alp[-1] )); do
|
||||
aln[-1]=()
|
||||
alp[-1]=()
|
||||
if (( $#tokens == alf[-1] )); then
|
||||
alf[-1]=()
|
||||
(( e = 0 ))
|
||||
fi
|
||||
done
|
||||
|
||||
while (( c-- > 0 )) || return; do
|
||||
token=$tokens[1]
|
||||
tokens[1]=()
|
||||
if (( $+galiases[$token] )); then
|
||||
(( $aln[(eI)p$token] )) && break
|
||||
s=$galiases[$token]
|
||||
n=p$token
|
||||
elif (( e )); then
|
||||
break
|
||||
elif (( $+aliases[$token] )); then
|
||||
(( $aln[(eI)p$token] )) && break
|
||||
s=$aliases[$token]
|
||||
n=p$token
|
||||
elif [[ $token == ?*.?* ]] && (( $+saliases[${token##*.}] )); then
|
||||
r=${token##*.}
|
||||
(( $aln[(eI)s$r] )) && break
|
||||
s=${saliases[$r]%% #}
|
||||
n=s$r
|
||||
else
|
||||
break
|
||||
fi
|
||||
aln+=$n
|
||||
alp+=$#tokens
|
||||
[[ $s == *' ' ]] && alf+=$#tokens
|
||||
(( ic )) && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s})
|
||||
done
|
||||
|
||||
case $token in
|
||||
'<<'(|-))
|
||||
state=h
|
||||
continue
|
||||
;;
|
||||
*('`'|['<>=$']'(')*)
|
||||
if [[ $token == ('`'[^'`']##'`'|'"`'[^'`']##'`"'|'$('[^')']##')'|'"$('[^')']##')"'|['<>=']'('[^')']##')') ]]; then
|
||||
s=${${token##('"'|)(['$<>']|)?}%%?('"'|)}
|
||||
(( ic )) && tokens+=(';' ${(Z+C+)s}) || tokens+=(';' ${(z)s})
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
case $state in
|
||||
*r)
|
||||
state[-1]=
|
||||
continue
|
||||
;;
|
||||
a)
|
||||
if [[ $token == $skip ]]; then
|
||||
if [[ $token == '{' ]]; then
|
||||
P9K_COMMANDS+=$cmd
|
||||
cmd=
|
||||
state=
|
||||
else
|
||||
skip='{'
|
||||
fi
|
||||
continue
|
||||
else
|
||||
state=t
|
||||
fi
|
||||
;& # fall through
|
||||
t|p*)
|
||||
if (( $+__p9k_pb_term[$token] )); then
|
||||
if [[ $token == '()' ]]; then
|
||||
state=
|
||||
else
|
||||
P9K_COMMANDS+=$cmd
|
||||
if [[ $token == '}' ]]; then
|
||||
state=a
|
||||
skip=always
|
||||
else
|
||||
skip=$__p9k_pb_term_skip[$token]
|
||||
state=${skip:+s}
|
||||
fi
|
||||
fi
|
||||
cmd=
|
||||
continue
|
||||
elif [[ $state == t ]]; then
|
||||
continue
|
||||
elif [[ $state == *x ]]; then
|
||||
if (( $+__p9k_pb_redirect[$token] )); then
|
||||
prev=
|
||||
state[-1]=r
|
||||
continue
|
||||
else
|
||||
state[-1]=
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
s)
|
||||
if [[ $token == $~skip ]]; then
|
||||
state=
|
||||
fi
|
||||
continue
|
||||
;;
|
||||
h)
|
||||
while (( $#tokens )); do
|
||||
(( e = ${tokens[(i)${(Q)token}]} ))
|
||||
if [[ $tokens[e-1] == ';' && $tokens[e+1] == ';' ]]; then
|
||||
tokens[1,e]=()
|
||||
break
|
||||
else
|
||||
tokens[1,e]=()
|
||||
fi
|
||||
done
|
||||
while (( $#alp && alp[-1] >= $#tokens )); do
|
||||
aln[-1]=()
|
||||
alp[-1]=()
|
||||
done
|
||||
state=t
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
if (( $+__p9k_pb_redirect[${token#<0-255>}] )); then
|
||||
state+=r
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ $token == *'$'* ]]; then
|
||||
if [[ $token == $~var ]]; then
|
||||
n=${${token##[^[:IDENT:]]}%%[^[:IDENT:]]}
|
||||
[[ $token == *'"' ]] && v=("${(P)n}") || v=(${(P)n})
|
||||
tokens[1,0]=(${(@qq)v})
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
case $state in
|
||||
'')
|
||||
if (( $+__p9k_pb_cmd_skip[$token] )); then
|
||||
skip=$__p9k_pb_cmd_skip[$token]
|
||||
[[ $token == '}' ]] && state=a || state=${skip:+s}
|
||||
continue
|
||||
fi
|
||||
if [[ $token == *=* ]]; then
|
||||
v=${(S)token/#(<->|([[:alpha:]_][[:IDENT:]]#(|'['*[^\\](\\\\)#']')))(|'+')=}
|
||||
if (( $#v < $#token )); then
|
||||
if [[ $v == '(' ]]; then
|
||||
state=s
|
||||
skip='\)'
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
: ${token::=${(Q)${~token}}}
|
||||
;;
|
||||
p2)
|
||||
if [[ -n $prev ]]; then
|
||||
prev=
|
||||
else
|
||||
: ${token::=${(Q)${~token}}}
|
||||
if [[ $token == '{'$~id'}' ]]; then
|
||||
state=p2x
|
||||
prev=$token
|
||||
else
|
||||
state=p
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
;& # fall through
|
||||
p)
|
||||
if [[ -n $prev ]]; then
|
||||
token=$prev
|
||||
prev=
|
||||
else
|
||||
: ${token::=${(Q)${~token}}}
|
||||
case $token in
|
||||
'{'$~id'}') prev=$token; state=px; continue;;
|
||||
[^-]*) ;;
|
||||
--) state=p1; continue;;
|
||||
$~skip) state=p2; continue;;
|
||||
*) continue;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
p1)
|
||||
if [[ -n $prev ]]; then
|
||||
token=$prev
|
||||
prev=
|
||||
else
|
||||
: ${token::=${(Q)${~token}}}
|
||||
if [[ $token == '{'$~id'}' ]]; then
|
||||
state=p1x
|
||||
prev=$token
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if (( $+__p9k_pb_precommand[$token] )); then
|
||||
prev=
|
||||
state=p
|
||||
skip=$__p9k_pb_precommand[$token]
|
||||
cmd+=$token$'\0'
|
||||
else
|
||||
state=t
|
||||
[[ $token == ('(('*'))'|'`'*'`'|'$'*|['<>=']'('*')'|*$'\0'*) ]] || cmd+=$token$'\0'
|
||||
fi
|
||||
done
|
||||
} always {
|
||||
[[ $state == (px|p1x) ]] && cmd+=$prev
|
||||
P9K_COMMANDS+=$cmd
|
||||
P9K_COMMANDS=(${(u)P9K_COMMANDS%$'\0'})
|
||||
}
|
||||
}
|
BIN
zsh/theme/internal/parser.zsh.zwc
Normal file
BIN
zsh/theme/internal/parser.zsh.zwc
Normal file
Binary file not shown.
2256
zsh/theme/internal/wizard.zsh
Normal file
2256
zsh/theme/internal/wizard.zsh
Normal file
File diff suppressed because it is too large
Load diff
219
zsh/theme/internal/worker.zsh
Normal file
219
zsh/theme/internal/worker.zsh
Normal file
|
@ -0,0 +1,219 @@
|
|||
# invoked in worker: _p9k_worker_main <pgid>
|
||||
function _p9k_worker_main() {
|
||||
mkfifo -- $_p9k__worker_file_prefix.fifo || return
|
||||
echo -nE - s$_p9k_worker_pgid$'\x1e' || return
|
||||
exec <$_p9k__worker_file_prefix.fifo || return
|
||||
zf_rm -- $_p9k__worker_file_prefix.fifo || return
|
||||
|
||||
local -i reset
|
||||
local req fd
|
||||
local -a ready
|
||||
local _p9k_worker_request_id
|
||||
local -A _p9k_worker_fds # fd => id$'\x1f'callback
|
||||
local -A _p9k_worker_inflight # id => inflight count
|
||||
|
||||
function _p9k_worker_reply() {
|
||||
print -nr -- e${(pj:\n:)@}$'\x1e' || kill -- -$_p9k_worker_pgid
|
||||
}
|
||||
|
||||
# usage: _p9k_worker_async <work> <callback>
|
||||
function _p9k_worker_async() {
|
||||
local fd async=$1
|
||||
sysopen -r -o cloexec -u fd <(() { eval $async; } && print -n '\x1e') || return
|
||||
(( ++_p9k_worker_inflight[$_p9k_worker_request_id] ))
|
||||
_p9k_worker_fds[$fd]=$_p9k_worker_request_id$'\x1f'$2
|
||||
}
|
||||
|
||||
trap '' PIPE
|
||||
|
||||
{
|
||||
while zselect -a ready 0 ${(k)_p9k_worker_fds}; do
|
||||
[[ $ready[1] == -r ]] || return
|
||||
for fd in ${ready:1}; do
|
||||
if [[ $fd == 0 ]]; then
|
||||
local buf=
|
||||
[[ -t 0 ]] # https://www.zsh.org/mla/workers/2020/msg00207.html
|
||||
if sysread -t 0 'buf[$#buf+1]'; then
|
||||
while [[ $buf != *$'\x1e' ]]; do
|
||||
sysread 'buf[$#buf+1]' || return
|
||||
done
|
||||
else
|
||||
(( $? == 4 )) || return
|
||||
fi
|
||||
for req in ${(ps:\x1e:)buf}; do
|
||||
_p9k_worker_request_id=${req%%$'\x1f'*}
|
||||
() { eval $req[$#_p9k_worker_request_id+2,-1] }
|
||||
(( $+_p9k_worker_inflight[$_p9k_worker_request_id] )) && continue
|
||||
print -rn -- d$_p9k_worker_request_id$'\x1e' || return
|
||||
done
|
||||
else
|
||||
local REPLY=
|
||||
while true; do
|
||||
if sysread -i $fd 'REPLY[$#REPLY+1]'; then
|
||||
[[ $REPLY == *$'\x1e' ]] || continue
|
||||
else
|
||||
(( $? == 5 )) || return
|
||||
break
|
||||
fi
|
||||
done
|
||||
local cb=$_p9k_worker_fds[$fd]
|
||||
_p9k_worker_request_id=${cb%%$'\x1f'*}
|
||||
unset "_p9k_worker_fds[$fd]"
|
||||
exec {fd}>&-
|
||||
if [[ $REPLY == *$'\x1e' ]]; then
|
||||
REPLY[-1]=""
|
||||
() { eval $cb[$#_p9k_worker_request_id+2,-1] }
|
||||
fi
|
||||
if (( --_p9k_worker_inflight[$_p9k_worker_request_id] == 0 )); then
|
||||
unset "_p9k_worker_inflight[$_p9k_worker_request_id]"
|
||||
print -rn -- d$_p9k_worker_request_id$'\x1e' || return
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
} always {
|
||||
kill -- -$_p9k_worker_pgid
|
||||
}
|
||||
}
|
||||
|
||||
# invoked in master: _p9k_worker_invoke <request-id> <list>
|
||||
function _p9k_worker_invoke() {
|
||||
[[ -n $_p9k__worker_resp_fd ]] || return
|
||||
local req=$1$'\x1f'$2$'\x1e'
|
||||
if [[ -n $_p9k__worker_req_fd && $+_p9k__worker_request_map[$1] == 0 ]]; then
|
||||
_p9k__worker_request_map[$1]=
|
||||
print -rnu $_p9k__worker_req_fd -- $req
|
||||
else
|
||||
_p9k__worker_request_map[$1]=$req
|
||||
fi
|
||||
}
|
||||
|
||||
function _p9k_worker_cleanup() {
|
||||
# __p9k_intro bugs out here in some cases for some reason.
|
||||
emulate -L zsh
|
||||
[[ $_p9k__worker_shell_pid == $sysparams[pid] ]] && _p9k_worker_stop
|
||||
return 0
|
||||
}
|
||||
|
||||
function _p9k_worker_stop() {
|
||||
# See comments in _p9k_worker_cleanup.
|
||||
emulate -L zsh
|
||||
add-zsh-hook -D zshexit _p9k_worker_cleanup
|
||||
[[ -n $_p9k__worker_resp_fd ]] && zle -F $_p9k__worker_resp_fd
|
||||
[[ -n $_p9k__worker_resp_fd ]] && exec {_p9k__worker_resp_fd}>&-
|
||||
[[ -n $_p9k__worker_req_fd ]] && exec {_p9k__worker_req_fd}>&-
|
||||
[[ -n $_p9k__worker_pid ]] && kill -- -$_p9k__worker_pid 2>/dev/null
|
||||
[[ -n $_p9k__worker_file_prefix ]] && zf_rm -f -- $_p9k__worker_file_prefix.fifo
|
||||
_p9k__worker_pid=
|
||||
_p9k__worker_req_fd=
|
||||
_p9k__worker_resp_fd=
|
||||
_p9k__worker_shell_pid=
|
||||
_p9k__worker_request_map=()
|
||||
return 0
|
||||
}
|
||||
|
||||
function _p9k_worker_receive() {
|
||||
eval "$__p9k_intro"
|
||||
|
||||
[[ -z $_p9k__worker_resp_fd ]] && return
|
||||
|
||||
{
|
||||
(( $# <= 1 )) || return
|
||||
|
||||
local buf resp
|
||||
|
||||
[[ -t $_p9k__worker_resp_fd ]] # https://www.zsh.org/mla/workers/2020/msg00207.html
|
||||
if sysread -i $_p9k__worker_resp_fd -t 0 'buf[$#buf+1]'; then
|
||||
while [[ $buf == *[^$'\x05\x1e']$'\x05'# ]]; do
|
||||
sysread -i $_p9k__worker_resp_fd 'buf[$#buf+1]' || return
|
||||
done
|
||||
else
|
||||
(( $? == 4 )) || return
|
||||
fi
|
||||
|
||||
local -i reset max_reset
|
||||
for resp in ${(ps:\x1e:)${buf//$'\x05'}}; do
|
||||
local arg=$resp[2,-1]
|
||||
case $resp[1] in
|
||||
d)
|
||||
local req=$_p9k__worker_request_map[$arg]
|
||||
if [[ -n $req ]]; then
|
||||
_p9k__worker_request_map[$arg]=
|
||||
print -rnu $_p9k__worker_req_fd -- $req || return
|
||||
else
|
||||
unset "_p9k__worker_request_map[$arg]"
|
||||
fi
|
||||
;;
|
||||
e)
|
||||
() { eval $arg }
|
||||
(( reset > max_reset )) && max_reset=reset
|
||||
;;
|
||||
s)
|
||||
[[ -z $_p9k__worker_req_fd ]] || return
|
||||
[[ $arg == <1-> ]] || return
|
||||
_p9k__worker_pid=$arg
|
||||
sysopen -w -o cloexec -u _p9k__worker_req_fd $_p9k__worker_file_prefix.fifo || return
|
||||
local req=
|
||||
for req in $_p9k__worker_request_map; do
|
||||
print -rnu $_p9k__worker_req_fd -- $req || return
|
||||
done
|
||||
_p9k__worker_request_map=({${(k)^_p9k__worker_request_map},''})
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if (( max_reset == 2 )); then
|
||||
_p9k__refresh_reason=worker
|
||||
_p9k_set_prompt
|
||||
_p9k__refresh_reason=''
|
||||
fi
|
||||
(( max_reset )) && _p9k_reset_prompt
|
||||
return 0
|
||||
} always {
|
||||
(( $? )) && _p9k_worker_stop
|
||||
}
|
||||
}
|
||||
|
||||
function _p9k_worker_start() {
|
||||
setopt monitor || return
|
||||
{
|
||||
[[ -n $_p9k__worker_resp_fd ]] && return
|
||||
|
||||
if [[ -n "$TMPDIR" && ( ( -d "$TMPDIR" && -w "$TMPDIR" ) || ! ( -d /tmp && -w /tmp ) ) ]]; then
|
||||
local tmpdir=$TMPDIR
|
||||
else
|
||||
local tmpdir=/tmp
|
||||
fi
|
||||
_p9k__worker_file_prefix=$tmpdir/p10k.worker.$EUID.$sysparams[pid].$EPOCHSECONDS
|
||||
|
||||
sysopen -r -o cloexec -u _p9k__worker_resp_fd <(
|
||||
exec 0</dev/null
|
||||
if [[ -n $_POWERLEVEL9K_WORKER_LOG_LEVEL ]]; then
|
||||
exec 2>$_p9k__worker_file_prefix.log
|
||||
setopt xtrace
|
||||
else
|
||||
exec 2>/dev/null
|
||||
fi
|
||||
builtin cd -q / || return
|
||||
zmodload zsh/zselect || return
|
||||
! { zselect -t0 || (( $? != 1 )) } || return
|
||||
local _p9k_worker_pgid=$sysparams[pid]
|
||||
_p9k_worker_main &
|
||||
{
|
||||
trap '' PIPE
|
||||
while syswrite $'\x05'; do zselect -t 1000; done
|
||||
zf_rm -f $_p9k__worker_file_prefix.fifo
|
||||
kill -- -$_p9k_worker_pgid
|
||||
} &
|
||||
exec =true) || return
|
||||
_p9k__worker_pid=$sysparams[procsubstpid]
|
||||
zle -F $_p9k__worker_resp_fd _p9k_worker_receive
|
||||
_p9k__worker_shell_pid=$sysparams[pid]
|
||||
add-zsh-hook zshexit _p9k_worker_cleanup
|
||||
} always {
|
||||
(( $? )) && _p9k_worker_stop
|
||||
}
|
||||
}
|
BIN
zsh/theme/internal/worker.zsh.zwc
Normal file
BIN
zsh/theme/internal/worker.zsh.zwc
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue