diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/icons.zsh | 10 | ||||
-rw-r--r-- | internal/notes.txt | 46 | ||||
-rw-r--r-- | internal/p10k.zsh | 204 |
3 files changed, 258 insertions, 2 deletions
diff --git a/internal/icons.zsh b/internal/icons.zsh index f5f4065b..fceb74df 100644 --- a/internal/icons.zsh +++ b/internal/icons.zsh @@ -38,6 +38,7 @@ function _p9k_init_icons() { FAIL_ICON '\u2718' # ✘ SYMFONY_ICON 'SF' NODE_ICON '\u2B22'$s # ⬢ + NODEJS_ICON '\u2B22'$s # ⬢ MULTILINE_FIRST_PROMPT_PREFIX '\u256D\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX '\u251C\U2500' # ├─ MULTILINE_LAST_PROMPT_PREFIX '\u2570\U2500 ' # ╰─ @@ -118,6 +119,7 @@ function _p9k_init_icons() { TERRAFORM_ICON 'tf' PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '.NET' + DOTNET_CORE_ICON '.NET' AZURE_ICON '\u2601' # ☁ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' @@ -155,6 +157,7 @@ function _p9k_init_icons() { FAIL_ICON '\u2718' # ✘ SYMFONY_ICON 'SF' NODE_ICON '\u2B22' # ⬢ + NODEJS_ICON '\u2B22' # ⬢ MULTILINE_FIRST_PROMPT_PREFIX '\u256D\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX '\u251C\U2500' # ├─ MULTILINE_LAST_PROMPT_PREFIX '\u2570\U2500 ' # ╰─ @@ -231,6 +234,7 @@ function _p9k_init_icons() { TERRAFORM_ICON 'tf' PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '.NET' + DOTNET_CORE_ICON '.NET' AZURE_ICON '\u2601' # ☁ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' @@ -275,6 +279,7 @@ function _p9k_init_icons() { FAIL_ICON "${CODEPOINT_OF_AWESOME_TIMES:+\\u$CODEPOINT_OF_AWESOME_TIMES}" SYMFONY_ICON 'SF' NODE_ICON '\u2B22' # ⬢ + NODEJS_ICON '\u2B22' # ⬢ MULTILINE_FIRST_PROMPT_PREFIX '\u256D\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX '\u251C\U2500' # ├─ MULTILINE_LAST_PROMPT_PREFIX '\u2570\U2500 ' # ╰─ @@ -348,6 +353,7 @@ function _p9k_init_icons() { TERRAFORM_ICON 'tf' PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '.NET' + DOTNET_CORE_ICON '.NET' AZURE_ICON '\u2601' # ☁ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' @@ -386,6 +392,7 @@ function _p9k_init_icons() { FAIL_ICON '\uF00D' # SYMFONY_ICON '\uE757' # NODE_ICON '\uE617 ' # + NODEJS_ICON '\uE617 ' # MULTILINE_FIRST_PROMPT_PREFIX '\u256D\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX '\u251C\U2500' # ├─ MULTILINE_LAST_PROMPT_PREFIX '\u2570\U2500 ' # ╰─ @@ -462,6 +469,7 @@ function _p9k_init_icons() { TERRAFORM_ICON '\uF1BB' # PROXY_ICON '\u2B82' # ⮂ DOTNET_ICON '\uE77F' # + DOTNET_CORE_ICON '\uE77F' # AZURE_ICON '\uFD03' # ﴃ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' @@ -499,6 +507,7 @@ function _p9k_init_icons() { FAIL_ICON '\u2718' # ✘ SYMFONY_ICON 'SF' NODE_ICON 'Node' + NODEJS_ICON 'Node' MULTILINE_FIRST_PROMPT_PREFIX '\u256D\U2500' # ╭─ MULTILINE_NEWLINE_PROMPT_PREFIX '\u251C\U2500' # ├─ MULTILINE_LAST_PROMPT_PREFIX '\u2570\U2500 ' # ╰─ @@ -575,6 +584,7 @@ function _p9k_init_icons() { TERRAFORM_ICON 'tf' PROXY_ICON '\u2194' # ↔ DOTNET_ICON '.NET' + DOTNET_CORE_ICON '.NET' AZURE_ICON '\u2601' # ☁ DIRENV_ICON '\u25BC' # ▼ FLUTTER_ICON 'F' diff --git a/internal/notes.txt b/internal/notes.txt index a37fbaa2..37b59191 100644 --- a/internal/notes.txt +++ b/internal/notes.txt @@ -8,3 +8,49 @@ disabling implicit reset on every eval in _p9k_worker_receive. - implement fake gitstatus api on top of vcs_info (or plain git?) + worker and use it if there is no gitstatus. + +## asdf + +- https://asdf-vm.com/#/core-configuration?id=environment-variables +- https://asdf-vm.com/#/core-configuration?id=tool-versions +- https://asdf-vm.com/#/core-configuration?id=homeasdfrc +- https://asdf-vm.com/#/plugins-create?id=binlist-legacy-filenames +- https://asdf-vm.com/#/plugins-create?id=binparse-legacy-file +- `print -lr -- ${ASDF_DATA_DIR:-~/.asdf}/plugins/*(/N:t)` +- `print -lr -- $(${ASDF_DATA_DIR:-~/.asdf}/plugins/ruby/bin/list-legacy-filenames)` +- `${ASDF_DATA_DIR:-~/.asdf}/plugins/ruby/bin/parse-legacy-file ~/powerlevel10k/test/foo/.ruby-version` + - if empty, keep looking +- ASDF_${upcase_name}_VERSION wins over everything +- deeper version overrides win +- .tool-versions wins over .ruby-version when in the same directory +- versions for different tools are looked up independently: if /foo/bar/.tool-versions doesn't + override "ruby" it's as if it doesn't exist as far as ruby version is concerned. +- after upglob look $HOME (same file patterns) +- finally look at $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME (single file; parse it like .tool-versions) +- ${ASDF_CONFIG_FILE:-~/.asdfrc} parsing: + opt="$( + grep -E "^\\s*legacy_version_file\\s*=\\s*" "$config_path" | + head | + awk -F '=' '{print $2}' | + sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + [[ $opt == yes ]] + +Stat caches: +- ${ASDF_CONFIG_FILE:-~/.asdfrc} => legacy_version_file (yes or no) +- ${ASDF_DATA_DIR:-~/.asdf}/plugins => list of plugins +- ${ASDF_DATA_DIR:-~/.asdf}/plugins/ruby/bin => list of relevant scripts + (list-legacy-filenames and parse-legacy-file) +- ${ASDF_DATA_DIR:-~/.asdf}/plugins/ruby/bin/list-legacy-filenames => list (or pattern made from it?) +- /foo/bar => { tool => version } (permanent cache via stat cache) + +--- + +typeset -ga _p9k_asdf_meta_files=( + ${ASDF_CONFIG_FILE:-~/.asdfrc} + ${ASDF_DATA_DIR:-~/.asdf}/plugins + ${ASDF_DATA_DIR:-~/.asdf}/plugins/*/bin{,/list-legacy-filenames,/parse-legacy-file}(N) +) +typeset -g _p9k_asdf_meta_sig # $ASDF_CONFIG_FILE ':' $ASDF_DATA_DIR ':' $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME ':' $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME ':' ${(j.:.)mtimes} + +typeset -g _p9k_asdf_file_pat # example: '(.tool-versions|.ruby-version)' +typeset -gA _p9k_asdf_file_info # .ruby-version => ruby1 ('1' means parse-legacy-file is present) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 7d690498..273096b4 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -532,7 +532,7 @@ _p9k_get_icon() { if [[ $2 == $'\1'* ]]; then _p9k_ret=${2[2,-1]} else - _p9k_param "$@" ${icons[$2]-$'\1'$3} + _p9k_param "$1" "$2" ${icons[$2]-$'\1'$3} if [[ $_p9k_ret == $'\1'* ]]; then _p9k_ret=${_p9k_ret[2,-1]} else @@ -1316,6 +1316,7 @@ _p9k_prompt_battery_set_args() { ;; Linux|Android) + # See https://sourceforge.net/projects/acpiclient. local -a bats=( /sys/class/power_supply/(BAT*|battery)/(FN) ) (( $#bats )) || return @@ -4519,6 +4520,185 @@ _p9k_prompt_wifi_sync() { fi } +function _p9k_asdf_check_meta() { + [[ -n $_p9k_asdf_meta_sig ]] || return + [[ -z $^_p9k_asdf_meta_non_files(#qN) ]] || return + local -a stat + zstat -A stat +mtime -- $_p9k_asdf_meta_files 2>/dev/null || return + [[ $_p9k_asdf_meta_sig == "$ASDF_CONFIG_FILE:$ASDF_DATA_DIR:${(j.:.)stat}" ]] || return +} + +function _p9k_asdf_init_meta() { + { + local -a files + local -i legacy_enabled + + _p9k_asdf_plugins=() + _p9k_asdf_file_info=() + + local cfg=${ASDF_CONFIG_FILE:-~/.asdfrc} + files+=$cfg + if [[ -f $cfg && -r $cfg ]]; then + # Config parser in adsf is very strange. + # + # This gives "yes": + # + # legacy_version_file = yes = no + # + # This gives "no": + # + # legacy_version_file = yes + # legacy_version_file = yes + # + # We do the same. + local lines=(${(@M)${(f)"$(<$cfg)"}:#[[:space:]]#legacy_version_file[[:space:]]#=*}) + if [[ $#lines == 1 && ${${(s:=:)lines[1]}[2]} == [[:space:]]#yes[[:space:]]# ]]; then + legacy_enabled=1 + fi + fi + + local root=${ASDF_DATA_DIR:-~/.asdf}/plugins + files+=$root + if [[ -d $root ]]; then + local plugin + for plugin in $root/[^[:space:]]##(N); do + _p9k_asdf_plugins+=${plugin:t} + if [[ ! -e $plugin/bin ]]; then + files+=$plugin/bin + else + local list_names=$plugin/bin/list-legacy-filenames + files+=$list_names + if [[ -x $list_names ]]; then + local -i has_parse=0 + if (( legacy_enabled )); then + local parse=$plugin/bin/parse-legacy-file + files+=$parse + [[ -x $parse ]] && has_parse=1 + fi + local name + for name in $($list_names 2>/dev/null); do + _p9k_asdf_file_info[$name]+="${plugin:t} $has_parse " + done + fi + fi + done + fi + + _p9k_asdf_meta_files=($^files(N)) + _p9k_asdf_meta_non_files=(${files:|_p9k_asdf_meta_files}) + + local -a stat + zstat -A stat +mtime -- $_p9k_asdf_meta_files 2>/dev/null || return + _p9k_asdf_meta_sig="$ASDF_CONFIG_FILE:$ASDF_DATA_DIR:${(j.:.)stat}" + } always { + (( $? )) || return + _p9k_asdf_meta_files=() + _p9k_asdf_meta_non_files=() + _p9k_asdf_meta_sig= + _p9k_asdf_plugins=() + _p9k_asdf_file_info=() + _p9k__asdf_dir2files=() + _p9k_asdf_file2versions=() + } +} + +function prompt_asdf() { + _p9k_asdf_check_meta || _p9k_asdf_init_meta || return + + local -A versions + local plugin + for plugin in $_p9k_asdf_plugins; do + local var=ASDF_${(U)plugin//-/_}_VERSION + local val="${(P)var}" + [[ -n $val ]] && versions[$plugin]=$val + done + + local -a stat + zstat -A stat +mtime ~ 2>/dev/null || return + local dirs=($_p9k__parent_dirs ~) + local mtimes=($_p9k__parent_mtimes $stat[1]) + + local elem + for elem in ${(@)${:-{1..$#dirs}}/(#m)*/${${:-$MATCH:$_p9k__asdf_dir2files[$dirs[MATCH]]}#$MATCH:$mtimes[MATCH]:}}; do + if [[ $elem == *:* ]]; then + local dir=$dirs[${elem%%:*}] + zstat -A stat +mtime $dir 2>/dev/null || return + local files=($dir/.tool-versions(N) $dir/${(k)^_p9k_asdf_file_info}(N)) + _p9k__asdf_dir2files[$dir]=$stat[1]:${(pj:\0:)files} + else + local files=(${(0)elem}) + fi + local file + for file in $files; do + zstat -A stat +mtime $file 2>/dev/null || return + local cached=$_p9k_asdf_file2versions[$file] + if [[ $cached == $stat[1]:* ]]; then + local file_versions=(${(0)${cached#*:}}) + else + local file_versions=() + if [[ $file == */.tool-versions ]]; then + { local lines=(${(@)${(f)"$(<$file)"}/\#*}) } 2>/dev/null + local line + for line in $lines; do + local words=($=line) + (( $#words > 1 && $_p9k_asdf_plugins[(Ie)$words[1]] )) || continue + file_versions+=($words[1] "${words[2,-1]}") + done + else + local plugin has_parse + for plugin has_parse in $=_p9k_asdf_file_info[$file:t]; do + if (( has_parse )); then + local v=($(${ASDF_DATA_DIR:-~/.asdf}/plugins/$plugin/bin/parse-legacy-file $file 2>/dev/null)) + else + { local v=($(<$file)) } 2>/dev/null + fi + (( $#v )) && file_versions+=($plugin "$v") + done + fi + _p9k_asdf_file2versions[$file]=$stat[1]:${(pj:\0:)file_versions} + fi + local plugin version + for plugin version in $file_versions; do + [[ -z $versions[$plugin] ]] && versions[$plugin]=$version + done + done + done + + if [[ -r $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME ]]; then + local file=$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME + zstat -A stat +mtime $file 2>/dev/null || return + local cached=$_p9k_asdf_file2versions[$file] + if [[ $cached == $stat[1]:* ]]; then + local file_versions=(${(0)${cached#*:}}) + else + local file_versions=() + { local lines=(${(@)${(f)"$(<$file)"}/\#*}) } 2>/dev/null + local line + for line in $lines; do + local words=($=line) + (( $#words > 1 && $_p9k_asdf_plugins[(Ie)$words[1]] )) || continue + file_versions+=($words[1] "${words[2,-1]}") + done + _p9k_asdf_file2versions[$file]=$stat[1]:${(pj:\0:)file_versions} + fi + local plugin version + for plugin version in $file_versions; do + [[ -z $versions[$plugin] ]] && versions[$plugin]=$version + done + fi + + local plugin version + for plugin version in ${(kv)versions}; do + local upper=${(U)plugin//-/_} + _p9k_get_icon $0_$upper ${upper}_ICON $plugin + _p9k_prompt_segment $0_$upper green $_p9k_color1 $'\1'$_p9k_ret 0 '' ${version//\%/%%} + done +} + +_p9k_prompt_asdf_init() { + typeset -g "_p9k__segment_cond_${_p9k_prompt_side}[_p9k_segment_index]"='${commands[asdf]:-${${+functions[asdf]}:#0}}' +} + # Use two preexec hooks to survive https://github.com/MichaelAquilina/zsh-you-should-use with # YSU_HARDCORE=1. See https://github.com/romkatv/powerlevel10k/issues/427. _p9k_preexec1() { @@ -4567,6 +4747,7 @@ function _p9k_prompt_net_iface_compute() { } function _p9k_prompt_net_iface_async() { + # netstat -inbI en0 local iface ip line var typeset -a iface2ip if (( $+commands[ifconfig] )); then @@ -5649,6 +5830,25 @@ typeset -g _p9k__param_pat typeset -g _p9k__param_sig _p9k_init_vars() { + typeset -ga _p9k_asdf_meta_files + typeset -ga _p9k_asdf_meta_non_files + typeset -g _p9k_asdf_meta_sig + + # example: (ruby lua chubaka) + typeset -ga _p9k_asdf_plugins + + # example: (.ruby-version "ruby 1 chubaka 0") + # + # - "1" means parse-legacy-file is present + # - "chubaka" is another plugin that claims to be able to parse .ruby-version + typeset -gA _p9k_asdf_file_info + + # dir => mtime ':' ${(pj:\0:)files} + typeset -gA _p9k__asdf_dir2files + + # file => mtime ':' ${(pj:\0:)versions} + typeset -gA _p9k_asdf_file2versions + # filepath => mtime ':' word typeset -gA _p9k__read_word_cache # filepath:prefix => mtime ':' versions @@ -6668,7 +6868,7 @@ _p9k_must_init() { [[ $sig == $_p9k__param_sig ]] && return 1 _p9k_deinit fi - _p9k__param_pat=$'v37\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1' + _p9k__param_pat=$'v38\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' |