diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/icons.zsh | 5 | ||||
-rw-r--r-- | internal/notes.txt | 9 | ||||
-rw-r--r-- | internal/p10k.zsh | 135 | ||||
-rw-r--r-- | internal/worker.zsh | 17 |
4 files changed, 120 insertions, 46 deletions
diff --git a/internal/icons.zsh b/internal/icons.zsh index 725da7d0..21d421b1 100644 --- a/internal/icons.zsh +++ b/internal/icons.zsh @@ -133,6 +133,7 @@ function _p9k_init_icons() { ERLANG_ICON 'erl' ELIXIR_ICON 'elixir' POSTGRES_ICON 'postgres' + PHP_ICON 'php' ) ;; 'awesome-fontconfig') @@ -251,6 +252,7 @@ function _p9k_init_icons() { ERLANG_ICON 'erl' ELIXIR_ICON 'elixir' POSTGRES_ICON 'postgres' + PHP_ICON 'php' ) ;; 'awesome-mapped-fontconfig') @@ -373,6 +375,7 @@ function _p9k_init_icons() { ERLANG_ICON 'erl' ELIXIR_ICON 'elixir' POSTGRES_ICON 'postgres' + PHP_ICON 'php' ) ;; 'nerdfont-complete'|'nerdfont-fontconfig') @@ -492,6 +495,7 @@ function _p9k_init_icons() { ERLANG_ICON '\uE7B1 ' # ELIXIR_ICON '\uE62D' # POSTGRES_ICON '\uE76E' # + PHP_ICON '\uE608' # ) ;; *) @@ -610,6 +614,7 @@ function _p9k_init_icons() { ERLANG_ICON 'erl' ELIXIR_ICON 'elixir' POSTGRES_ICON 'postgres' + PHP_ICON 'php' ) ;; esac diff --git a/internal/notes.txt b/internal/notes.txt index a873eb83..de86abc6 100644 --- a/internal/notes.txt +++ b/internal/notes.txt @@ -17,3 +17,12 @@ 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 make directory shorter? mention POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER, + POWERLEVEL9K_DIR_MAX_LENGTH and truncate_to_last. diff --git a/internal/p10k.zsh b/internal/p10k.zsh index ccd75625..b51eea47 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -1766,8 +1766,10 @@ prompt_dir() { fi ;; truncate_to_last) - fake_first=$(($#parts > 1)) - parts[1,-2]=() + if [[ $#parts -gt 2 || $p[1] != / && $#parts -gt 1 ]]; then + fake_first=1 + parts[1,-2]=() + fi ;; truncate_to_first_and_last) if (( shortenlen > 0 )); then @@ -2100,12 +2102,16 @@ prompt_vpn_ip() { ################################################################ # Segment to display laravel version prompt_laravel_version() { - local laravel_version="$(php artisan --version 2> /dev/null)" - if [[ -n "${laravel_version}" && "${laravel_version}" =~ "Laravel Framework" ]]; then - # Strip out everything but the version - laravel_version="${laravel_version//Laravel Framework /}" - _p9k_prompt_segment "$0" "maroon" "white" 'LARAVEL_ICON' 0 '' "${laravel_version//\%/%%}" + _p9k_upglob artisan && return + local dir=$_p9k__parent_dirs[$?] + local app=$dir/vendor/laravel/framework/src/Illuminate/Foundation/Application.php + [[ -r $app ]] || return + if ! _p9k_cache_stat_get $0 $dir/artisan $app; then + local v="$(php $dir/artisan --version 2> /dev/null)" + _p9k_cache_stat_set "${${(M)v:#Laravel Framework *}#Laravel Framework }" fi + [[ -n $_p9k__cache_val[1] ]] || return + _p9k_prompt_segment "$0" "maroon" "white" 'LARAVEL_ICON' 0 '' "${_p9k__cache_val[1]//\%/%%}" } _p9k_prompt_laravel_version_init() { @@ -2425,10 +2431,13 @@ instant_prompt_os_icon() { prompt_os_icon; } ################################################################ # Segment to display PHP version number prompt_php_version() { + if (( _POWERLEVEL9K_PHP_VERSION_PROJECT_ONLY )); then + _p9k_upglob 'composer.json|*.php' && return + fi _p9k_cached_cmd_stdout php --version || return - [[ $_p9k__ret == (#b)(*$'\n')#(PHP [[:digit:].]##)* ]] || return + [[ $_p9k__ret == (#b)(*$'\n')#'PHP '([[:digit:].]##)* ]] || return local v=$match[2] - _p9k_prompt_segment "$0" "fuchsia" "grey93" '' 0 '' "${v//\%/%%}" + _p9k_prompt_segment "$0" "fuchsia" "grey93" 'PHP_ICON' 0 '' "${v//\%/%%}" } _p9k_prompt_php_version_init() { @@ -2548,6 +2557,56 @@ _p9k_prompt_rbenv_init() { typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[rbenv]:-${${+functions[rbenv]}:#0}}' } +function _p9k_phpenv_global_version() { + _p9k_read_word ${PHPENV_ROOT:-$HOME/.phpenv}/version || _p9k__ret=system +} + +prompt_phpenv() { + if [[ -n $PHPENV_VERSION ]]; then + (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)shell]} )) || return + local v=$PHPENV_VERSION + else + (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)local|global]} )) || return + if [[ $PHPENV_DIR == (|.) ]]; then + _p9k_upglob .php-version + local -i idx=$? + if (( idx )) && _p9k_read_word $_p9k__parent_dirs[idx]/.php-version; then + (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)local]} )) || return + else + _p9k__ret= + fi + else + _p9k__ret= + [[ $PHPENV_DIR == /* ]] && local dir=$PHPENV_DIR || local dir="$_p9k__cwd_a/$PHPENV_DIR" + while true; do + if _p9k_read_word $dir/.php-version; then + (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)local]} )) || return + break + fi + [[ $dir == / ]] && break + dir=${dir:h} + done + fi + if [[ -z $_p9k__ret ]]; then + (( _POWERLEVEL9K_PHPENV_PROMPT_ALWAYS_SHOW )) || return + (( ${_POWERLEVEL9K_PHPENV_SOURCES[(I)global]} )) || return + _p9k_phpenv_global_version + fi + local v=$_p9k__ret + fi + + if (( !_POWERLEVEL9K_PHPENV_PROMPT_ALWAYS_SHOW )); then + _p9k_phpenv_global_version + [[ $v == $_p9k__ret ]] && return + fi + + _p9k_prompt_segment "$0" "magenta" "$_p9k_color1" 'PHP_ICON' 0 '' "${v//\%/%%}" +} + +_p9k_prompt_phpenv_init() { + typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[phpenv]:-${${+functions[phpenv]}:#0}}' +} + function _p9k_luaenv_global_version() { _p9k_read_word ${LUAENV_ROOT:-$HOME/.luaenv}/version || _p9k__ret=system } @@ -5565,7 +5624,7 @@ function _p9k_clear_instant_prompt() { print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed] fi prompt_opts=(percent subst sp cr) - if [[ $_POWERLEVEL9K_DISABLE_INSTANT_PROMPT == 0 && -o prompt_cr ]]; then + if [[ $_POWERLEVEL9K_DISABLE_INSTANT_PROMPT == 0 && $__p9k_instant_prompt_active == 2 ]]; then >&2 echo -E - "" >&2 echo -E - "${(%):-[%1FERROR%f]: When using Powerlevel10k with instant prompt, %Bprompt_cr%b must be unset.}" >&2 echo -E - "" @@ -5646,16 +5705,12 @@ function _p9k_maybe_dump() { } function _p9k_on_expand() { - (( _p9k__expanded && ! $+__p9k_instant_prompt_active )) && return + (( _p9k__expanded && ! ${+__p9k_instant_prompt_active} )) && return - () { - eval "$__p9k_intro" + eval "$__p9k_intro" + if (( ! _p9k__expanded )); then _p9k_maybe_dump - (( $+__p9k_instant_prompt_active )) && _p9k_clear_instant_prompt - - (( _p9k__expanded )) && return - _p9k__expanded=1 if (( ! $+P9K_TTY )); then typeset -gx P9K_TTY=old @@ -5698,15 +5753,24 @@ function _p9k_on_expand() { fi fi - if [[ -z $_p9k__last_tty ]]; then - _p9k_wrap_widgets - (( $+functions[p10k-on-init] )) && p10k-on-init - fi + [[ -z $_p9k__last_tty ]] && _p9k_wrap_widgets + fi + + if (( $+__p9k_instant_prompt_active )); then + _p9k_clear_instant_prompt + unset __p9k_instant_prompt_active + fi + + if (( ! _p9k__expanded )); then + _p9k__expanded=1 + + [[ -z $_p9k__last_tty && $+functions[p10k-on-init] == 1 ]] && p10k-on-init local pat idx var for pat idx var in $_p9k_show_on_command; do _p9k_display_segment $idx $var hide done + (( $+functions[p10k-on-pre-prompt] )) && p10k-on-pre-prompt __p9k_reset_state=0 @@ -5728,12 +5792,6 @@ function _p9k_on_expand() { } fi fi - } - - if (( $+__p9k_instant_prompt_active )); then - unset __p9k_instant_prompt_active - unsetopt localoptions - setopt prompt_sp prompt_cr fi } functions -M _p9k_on_expand @@ -5857,12 +5915,9 @@ _p9k_precmd() { _p9k_precmd_impl - unsetopt localoptions - setopt nopromptbang prompt_percent prompt_subst - - if (( ! $+functions[TRAPINT] )); then - trap '_p9k_trapint; return 130' INT - fi + (( ${+functions[TRAPINT]} )) || trap '_p9k_trapint; return 130' INT + [[ ${+__p9k_instant_prompt_active} == 0 || -o no_prompt_cr ]] || __p9k_instant_prompt_active=2 + setopt no_local_options no_prompt_bang prompt_percent prompt_subst prompt_cr prompt_sp } function _p9k_reset_prompt() { @@ -6285,11 +6340,14 @@ _p9k_init_params() { esac _p9k_declare -b POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW 0 _p9k_declare -b POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY 0 + _p9k_declare -b POWERLEVEL9K_PHP_VERSION_PROJECT_ONLY 0 _p9k_declare -b POWERLEVEL9K_DOTNET_VERSION_PROJECT_ONLY 1 _p9k_declare -b POWERLEVEL9K_GO_VERSION_PROJECT_ONLY 1 _p9k_declare -b POWERLEVEL9K_RUST_VERSION_PROJECT_ONLY 1 _p9k_declare -b POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW 0 _p9k_declare -a POWERLEVEL9K_RBENV_SOURCES -- shell local global + _p9k_declare -b POWERLEVEL9K_PHPENV_PROMPT_ALWAYS_SHOW 0 + _p9k_declare -a POWERLEVEL9K_PHPENV_SOURCES -- shell local global _p9k_declare -b POWERLEVEL9K_LUAENV_PROMPT_ALWAYS_SHOW 0 _p9k_declare -a POWERLEVEL9K_LUAENV_SOURCES -- shell local global _p9k_declare -b POWERLEVEL9K_JENV_PROMPT_ALWAYS_SHOW 0 @@ -6961,7 +7019,7 @@ _p9k_must_init() { [[ $sig == $_p9k__param_sig ]] && return 1 _p9k_deinit fi - _p9k__param_pat=$'v46\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1' + _p9k__param_pat=$'v49\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1' _p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\1' _p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1' _p9k__param_pat+=$'$DEFAULT_USER\1${ZLE_RPROMPT_INDENT:-1}\1$P9K_SSH\1$__p9k_ksh_arrays' @@ -7396,14 +7454,16 @@ _p9k_setup() { prompt_opts+=cr fi - eval "$__p9k_intro" prompt_powerlevel9k_teardown __p9k_enabled=1 typeset -ga preexec_functions=(_p9k_preexec1 $preexec_functions _p9k_preexec2) typeset -ga precmd_functions=(_p9k_do_nothing $precmd_functions _p9k_precmd) } -prompt_powerlevel9k_setup() { _p9k_setup } +prompt_powerlevel9k_setup() { + eval "$__p9k_intro" + _p9k_setup +} prompt_powerlevel9k_teardown() { eval "$__p9k_intro" @@ -7734,7 +7794,8 @@ function p10k() { powerlevel10k_plugin_unload() { prompt_powerlevel9k_teardown; } function p10k-instant-prompt-finalize() { - (( ! __p9k_instant_prompt_active )) || unsetopt localoptions prompt_cr + unsetopt local_options + (( ${+__p9k_instant_prompt_active} )) && unsetopt prompt_cr prompt_sp || setopt prompt_cr prompt_sp } autoload -Uz add-zsh-hook diff --git a/internal/worker.zsh b/internal/worker.zsh index 34398faa..10d0c93a 100644 --- a/internal/worker.zsh +++ b/internal/worker.zsh @@ -5,7 +5,7 @@ function _p9k_worker_main() { exec 0<$_p9k__worker_file_prefix.fifo || return zf_rm $_p9k__worker_file_prefix.fifo || return - local -i reset n + local -i reset local req fd local -a ready local _p9k_worker_request_id @@ -34,9 +34,9 @@ function _p9k_worker_main() { if [[ $fd == 0 ]]; then local buf= [[ -t 0 ]] # https://www.zsh.org/mla/workers/2020/msg00207.html - if sysread -c n -t 0 'buf[$#buf+1]'; then - while [[ $buf != *$'\x1e' ]] || (( n == 8192 )); do - sysread -c n 'buf[$#buf+1]' || return + if sysread -t 0 'buf[$#buf+1]'; then + while [[ $buf != *$'\x1e' ]]; do + sysread 'buf[$#buf+1]' || return done else (( $? == 4 )) || return @@ -116,12 +116,11 @@ function _p9k_worker_receive() { (( $# <= 1 )) || return local buf resp - local -i n [[ -t $_p9k__worker_resp_fd ]] # https://www.zsh.org/mla/workers/2020/msg00207.html - if sysread -i $_p9k__worker_resp_fd -c n -t 0 'buf[$#buf+1]'; then - while [[ ${buf%%$'\x05'#} != (|*$'\x1e') ]] || (( n == 8192 )); do - sysread -i $_p9k__worker_resp_fd -c n 'buf[$#buf+1]' || return + 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 @@ -177,7 +176,7 @@ function _p9k_worker_start() { setopt monitor || return { [[ -n $_p9k__worker_resp_fd ]] && return - _p9k__worker_file_prefix=${TMPDIR:-/tmp}/p10k.worker.$EUID.$$.$EPOCHSECONDS + _p9k__worker_file_prefix=${TMPDIR:-/tmp}/p10k.worker.$EUID.$sysparams[pid].$EPOCHSECONDS sysopen -r -o cloexec -u _p9k__worker_resp_fd <( if [[ -n $_POWERLEVEL9K_WORKER_LOG_LEVEL ]]; then |