From 0a05733e9d28720d7aaef1c4aa41ebdb35fd5ea5 Mon Sep 17 00:00:00 2001 From: mattmc3 Date: Mon, 31 Jan 2022 20:53:19 -0500 Subject: [PATCH] Cache output of 'brew --prefix' --- modules/completion/init.zsh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/completion/init.zsh b/modules/completion/init.zsh index fc5cfd45..5ac1ff54 100644 --- a/modules/completion/init.zsh +++ b/modules/completion/init.zsh @@ -15,11 +15,19 @@ fi fpath=(${0:h}/external/src $fpath) # Add completion for keg-only brewed curl when available. -if (( $+commands[brew] )) \ - && [[ -d "${curl_prefix::="$(brew --prefix 2> /dev/null)"/opt/curl}" ]]; then - fpath=($curl_prefix/share/zsh/site-functions $fpath) +if (( $+commands[brew] )); then + # 'brew --prefix' is slow; cache its output + cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/brew-cache.zsh" + if [[ "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" || ! -s "$cache_file" ]]; then + mkdir -p "$cache_file:h" + echo "brew_prefix=$(brew --prefix 2> /dev/null)" >! "$cache_file" + fi + source "$cache_file" + if [[ -d "${curl_site_functions::=$brew_prefix/opt/curl/share/zsh/site-functions}" ]]; then + fpath=($curl_site_functions $fpath) + fi + unset cache_file brew_prefix curl_site_functions fi -unset curl_prefix # # Options