From 412015d3749fb35c09f26f0a3f8d65d92d9a58ac Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 13 Feb 2021 17:31:01 +0200 Subject: [PATCH] [zsh] parse rustup settings with a zsh script instead to further improve performance --- zsh/path.zsh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/zsh/path.zsh b/zsh/path.zsh index 303370e..fff9b36 100644 --- a/zsh/path.zsh +++ b/zsh/path.zsh @@ -77,25 +77,28 @@ if [[ -f ~/.rustup/settings.toml ]]; then # use of rustup's CLI. Also a shortcut is taken: strings aren't unescaped # because Rust toolchain names don't need escaping in strings. # See also . - if rust_toolchain="$( - awk ' - match($0, /^default_toolchain = "(.+)"$/, matches) { - print matches[1]; - exit; - } - /^\[.+\]$/ { - exit; - } - ' ~/.rustup/settings.toml - )" && [[ -n "$rust_toolchain" ]]; then + rust_toolchain="" + < ~/.rustup/settings.toml while IFS= read -r line; do + if [[ "$line" =~ '^default_toolchain = "(.+)"$' ]]; then + rust_toolchain="${match[1]}" + break + elif [[ "$line" == \[*\] ]]; then + break + fi + done; unset line + + if [[ -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 path_prepend ld_library_path "$rust_sysroot"/lib + unset rust_sysroot fi - unset rust_toolchain rust_sysroot + + unset rust_toolchain fi + path_prepend path ~/.cargo/bin # add my binaries and completions