1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-29 06:40:08 +00:00

add POWERLEVEL9K_ASDF_${plugin}_{SOURCES,PROMPT_ALWAYS_SHOW} with fallback to POWERLEVEL9K_ASDF_{SOURCES,PROMPT_ALWAYS_SHOW}

This commit is contained in:
romkatv 2020-02-07 11:38:18 +01:00
parent abbe7f361c
commit 8be5750ccc

View file

@ -4577,6 +4577,7 @@ function _p9k_asdf_init_meta() {
fi fi
local name local name
for name in $($list_names 2>/dev/null); do for name in $($list_names 2>/dev/null); do
[[ $name == (*/*|*:*|.tool-versions) ]] && continue
_p9k_asdf_file_info[$name]+="${plugin:t} $has_parse " _p9k_asdf_file_info[$name]+="${plugin:t} $has_parse "
done done
fi fi
@ -4602,21 +4603,63 @@ function _p9k_asdf_init_meta() {
} }
} }
# Usage: _p9k_asdf_parse_version_file <file> <is_legacy>
#
# Mutates `versions` on success.
function _p9k_asdf_parse_version_file() {
local file=$1
local is_legacy=$2
local -a stat
zstat -A stat +mtime $file 2>/dev/null || return
if (( is_legacy )); then
local plugin has_parse
for plugin has_parse in $=_p9k_asdf_file_info[$file:t]; do
(( $+versions[$plugin] )) && continue
local cached=$_p9k_asdf_file2versions[$file:$plugin]
if [[ $cached == $stat[1]:* ]]; then
versions[$plugin]=${cached#*:}
else
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 )) && versions[$plugin]="$v"
_p9k_asdf_file2versions[$file:$plugin]=$stat[1]:"$v"
fi
done
else
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
(( $+versions[$plugin] )) || versions[$plugin]=$version
done
fi
return 0
}
function prompt_asdf() { function prompt_asdf() {
_p9k_asdf_check_meta || _p9k_asdf_init_meta || return _p9k_asdf_check_meta || _p9k_asdf_init_meta || return
local -A versions 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 local -a stat
zstat -A stat +mtime ~ 2>/dev/null || return zstat -A stat +mtime ~ 2>/dev/null || return
local dirs=($_p9k__parent_dirs ~) local dirs=($_p9k__parent_dirs ~)
local mtimes=($_p9k__parent_mtimes $stat[1]) local mtimes=($_p9k__parent_mtimes $stat[1])
local -i has_global
local elem local elem
for elem in ${(@)${:-{1..$#dirs}}/(#m)*/${${:-$MATCH:$_p9k__asdf_dir2files[$dirs[MATCH]]}#$MATCH:$mtimes[MATCH]:}}; do for elem in ${(@)${:-{1..$#dirs}}/(#m)*/${${:-$MATCH:$_p9k__asdf_dir2files[$dirs[MATCH]]}#$MATCH:$mtimes[MATCH]:}}; do
@ -4628,68 +4671,72 @@ function prompt_asdf() {
else else
local files=(${(0)elem}) local files=(${(0)elem})
fi fi
if [[ ${files[1]:h} == ~ ]]; then
has_global=1
local -A local_versions=(${(kv)versions})
versions=()
fi
local file local file
for file in $files; do for file in $files; do
zstat -A stat +mtime $file 2>/dev/null || return [[ $file == */.tool-versions ]]
local cached=$_p9k_asdf_file2versions[$file] _p9k_asdf_parse_version_file $file $? || return
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 done
else done
local plugin has_parse
for plugin has_parse in $=_p9k_asdf_file_info[$file:t]; do if (( ! has_global )); then
if (( has_parse )); then has_global=1
local v=($(${ASDF_DATA_DIR:-~/.asdf}/plugins/$plugin/bin/parse-legacy-file $file 2>/dev/null)) local -A local_versions=(${(kv)versions})
else versions=()
{ local v=($(<$file)) } 2>/dev/null
fi 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 if [[ -r $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME ]]; then
local file=$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME _p9k_asdf_parse_version_file $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME 0 || return
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 fi
local plugin version local plugin
for plugin version in ${(kv)versions}; do for plugin in $_p9k_asdf_plugins; do
local upper=${(U)plugin//-/_} local upper=${(U)plugin//-/_}
local var=POWERLEVEL9K_ASDF_${upper}_SOURCES
if (( $+parameters[$var] )); then
local sources=(${(P)var})
else
var=POWERLEVEL9K_ASDF_SOURCES
if (( $+parameters[$var] )); then
local sources=(${(P)var})
else
local sources=(shell local global)
fi
fi
var=ASDF_${upper}_VERSION
local version="${(P)var}"
if [[ -n $version ]]; then
(( $sources[(I)shell] )) || continue
else
version=$local_versions[$plugin]
if [[ -n $version ]]; then
(( $sources[(I)local] )) || continue
else
version=$versions[$plugin]
[[ -n $version ]] || continue
(( $sources[(I)global] )) || continue
fi
fi
if [[ $version == $versions[$plugin] ]]; then
var=POWERLEVEL9K_ASDF_${upper}_PROMPT_ALWAYS_SHOW
if (( $+parameters[$var] )); then
[[ ${(P)var} == true ]] || continue
else
var=POWERLEVEL9K_ASDF_PROMPT_ALWAYS_SHOW
if (( $+parameters[$var] )); then
[[ ${(P)var} == true ]] || continue
else
continue
fi
fi
fi
_p9k_get_icon $0_$upper ${upper}_ICON $plugin _p9k_get_icon $0_$upper ${upper}_ICON $plugin
_p9k_prompt_segment $0_$upper green $_p9k_color1 $'\1'$_p9k_ret 0 '' ${version//\%/%%} _p9k_prompt_segment $0_$upper green $_p9k_color1 $'\1'$_p9k_ret 0 '' ${version//\%/%%}
done done
@ -6868,7 +6915,7 @@ _p9k_must_init() {
[[ $sig == $_p9k__param_sig ]] && return 1 [[ $sig == $_p9k__param_sig ]] && return 1
_p9k_deinit _p9k_deinit
fi fi
_p9k__param_pat=$'v38\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1' _p9k__param_pat=$'v39\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1'
_p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\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+=$'$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' _p9k__param_pat+=$'$DEFAULT_USER\1${ZLE_RPROMPT_INDENT:-1}\1$P9K_SSH\1$__p9k_ksh_arrays'