mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[zsh] improve path.zsh loading speed by not calling the entire rustc
The effects of this were very significant on my good ol' winchester.
This commit is contained in:
parent
3f40b413f3
commit
4ad73c7154
1 changed files with 25 additions and 10 deletions
35
zsh/path.zsh
35
zsh/path.zsh
|
@ -68,17 +68,32 @@ export GOPATH=~/go
|
||||||
path_prepend path "$GOPATH/bin"
|
path_prepend path "$GOPATH/bin"
|
||||||
|
|
||||||
# Rust
|
# Rust
|
||||||
path_prepend path ~/.cargo/bin
|
if [[ -f ~/.rustup/settings.toml ]]; then
|
||||||
# check if the Rust toolchain was installed via rustup
|
# Make a low-effort attempt at quickly extracting the selected Rust toolchain
|
||||||
if rustup_home="$(rustup show home 2> /dev/null)" &&
|
# from rustup's settings. The TOML file is obviously assumed to be well-formed
|
||||||
rust_sysroot="$(rustc --print sysroot 2> /dev/null)" &&
|
# and syntactically correct because virtually always it's manipulated with the
|
||||||
[[ -d "$rustup_home" && -d "$rust_sysroot" && "$rust_sysroot" == "$rustup_home"/* ]]
|
# use of rustup's CLI. Also a shortcut is taken: strings aren't unescaped
|
||||||
then
|
# because Rust toolchain names don't need escaping in strings.
|
||||||
# add paths of the selected Rust toolchain
|
# See also <https://github.com/toml-lang/toml/blob/master/toml.abnf>.
|
||||||
path_prepend fpath "$rust_sysroot/share/zsh/site-functions"
|
if rust_toolchain="$(
|
||||||
path_prepend manpath "$rust_sysroot/share/man"
|
awk '
|
||||||
|
match($0, /^default_toolchain = "(.+)"$/, matches) {
|
||||||
|
print matches[1];
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
/^\[.+\]$/ {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
' ~/.rustup/settings.toml
|
||||||
|
)" && [[ -n "$rust_toolchain" ]]; then
|
||||||
|
rust_sysroot=~/.rustup/toolchains/"$rust_toolchain"
|
||||||
|
path_prepend path "$rust_sysroot"/bin
|
||||||
|
path_prepend fpath "$rust_sysroot"/zsh/site-functions
|
||||||
|
path_prepend manpath "$rust_sysroot"/share/man
|
||||||
|
fi
|
||||||
|
unset rust_toolchain rust_sysroot
|
||||||
fi
|
fi
|
||||||
unset rustup_home rust_sysroot
|
path_prepend path ~/.cargo/bin
|
||||||
|
|
||||||
# add my binaries and completions
|
# add my binaries and completions
|
||||||
path_prepend path "${ZSH_DOTFILES:h}/scripts"
|
path_prepend path "${ZSH_DOTFILES:h}/scripts"
|
||||||
|
|
Loading…
Reference in a new issue