make rust_version segment compatible with the new rustup toolchain file (#2413)

pull/2472/head
Roman Perepelitsa 1 year ago
parent 862440ae11
commit c7fa7d6748

@ -3186,68 +3186,55 @@ instant_prompt_root_indicator() { prompt_root_indicator; }
################################################################ ################################################################
# Segment to display Rust version number # Segment to display Rust version number
prompt_rust_version() { prompt_rust_version() {
unset P9K_RUST_VERSION local -i len=$#_p9k__prompt _p9k__has_upglob
if (( _POWERLEVEL9K_RUST_VERSION_PROJECT_ONLY )); then _p9k_prompt_segment $0 darkorange $_p9k_color1 RUST_ICON 1 '$P9K_RUST_VERSION' '${P9K_RUST_VERSION//\%/%%}'
_p9k_upglob Cargo.toml -. && return (( _p9k__has_upglob )) || typeset -g "_p9k__segment_val_${_p9k__prompt_side}[_p9k__segment_index]"=$_p9k__prompt[len+1,-1]
fi }
local rustc=$commands[rustc] toolchain deps=()
if (( $+commands[ldd] )); then function _p9k_prompt_rust_version_init() {
if ! _p9k_cache_stat_get $0_so $rustc; then _p9k__async_segments_compute+='_p9k_rust_version_prefetch'
local line so typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[rustc]'
for line in "${(@f)$(ldd $rustc 2>/dev/null)}"; do }
[[ $line == (#b)[[:space:]]#librustc_driver[^[:space:]]#.so' => '(*)' (0x'[[:xdigit:]]#')' ]] || continue
so=$match[1] _p9k_rust_version_prefetch() {
break local rustc=$commands[rustc]
done if [[ -z $rustc ]] ||
_p9k_cache_stat_set "$so" { (( _POWERLEVEL9K_RUST_VERSION_PROJECT_ONLY )) && _p9k_upglob Cargo.toml -. }; then
fi unset P9K_RUST_VERSION
deps+=$_p9k__cache_val[1] return
fi
if (( $+commands[rustup] )); then
local rustup=$commands[rustup]
local rustup_home=${RUSTUP_HOME:-~/.rustup}
local cfg=($rustup_home/settings.toml(.N))
deps+=($cfg $rustup_home/update-hashes/*(.N))
if [[ -z ${toolchain::=$RUSTUP_TOOLCHAIN} ]]; then
if ! _p9k_cache_stat_get $0_overrides $rustup $cfg; then
local lines=(${(f)"$(rustup override list 2>/dev/null)"})
if [[ $lines[1] == "no overrides" ]]; then
_p9k_cache_stat_set
else
local MATCH
local keys=(${(@)${lines%%[[:space:]]#[^[:space:]]#}/(#m)*/${(b)MATCH}/})
local vals=(${(@)lines/(#m)*/$MATCH[(I)/] ${MATCH##*[[:space:]]}})
_p9k_cache_stat_set ${keys:^vals}
fi
fi
local -A overrides=($_p9k__cache_val)
_p9k_upglob rust-toolchain -.
local dir=$_p9k__parent_dirs[$?]
local -i n m=${dir[(I)/]}
local pair
for pair in ${overrides[(K)$_p9k__cwd/]}; do
n=${pair%% *}
(( n <= m )) && continue
m=n
toolchain=${pair#* }
done
if [[ -z $toolchain && -n $dir ]]; then
_p9k_read_word $dir/rust-toolchain
toolchain=$_p9k__ret
fi
fi
fi fi
if ! _p9k_cache_stat_get $0_v$toolchain $rustc $deps; then _p9k_worker_invoke rust_version \
_p9k_cache_stat_set "$($rustc --version 2>/dev/null)" "_p9k_prompt_rust_version_compute ${(q)P9K_RUST_VERSION} ${(q)rustc} ${(q)_p9k__cwd_a}"
}
_p9k_prompt_rust_version_compute() {
_p9k_worker_async \
"_p9k_prompt_rust_version_async ${(q)1} ${(q)2} ${(q)3}" \
_p9k_prompt_rust_version_sync
}
_p9k_prompt_rust_version_async() {
typeset -g P9K_RUST_VERSION=$1
local rustc=$2 cwd=$3 v
if pushd -q -- $cwd; then
{
v=${${"$($rustc --version)"#rustc }%% *} || v=
} always {
popd -q
}
fi fi
local v=${${_p9k__cache_val[1]#rustc }%% *}
[[ -n $v ]] || return [[ $v != $P9K_RUST_VERSION ]] || return
typeset -g P9K_RUST_VERSION=$_p9k__cache_val[1] typeset -g P9K_RUST_VERSION=$v
_p9k_prompt_segment "$0" "darkorange" "$_p9k_color1" 'RUST_ICON' 0 '' "${v//\%/%%}" _p9k_print_params P9K_RUST_VERSION
echo -E - 'reset=1'
} }
_p9k_prompt_rust_version_init() { _p9k_prompt_rust_version_sync() {
typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[rustc]' if [[ -n $REPLY ]]; then
eval $REPLY
_p9k_worker_reply $REPLY
fi
} }
# RSpec test ratio # RSpec test ratio

Loading…
Cancel
Save