mirror of
https://github.com/dcarrillo/prezto.git
synced 2025-10-14 15:49:09 +00:00
node: Optimize completions for loading lazily on demand
Move `grunt` and `gulp` to separate completion definitions wrapping `grunt --completion=zsh` and `gulp --completion=zsh` respectively. Since the completions are loaded lazily on demand, they avoid the performance overhead during Zsh initialization. Additionally, remove `npm` completion since it is already bundled with Zsh for quite a while.
This commit is contained in:
committed by
Indrajit Raychaudhuri
parent
f84075b8d4
commit
9f37fc9841
@@ -5,6 +5,7 @@
|
||||
# Authors:
|
||||
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
||||
# Zeh Rizzatti <zehrizzatti@gmail.com>
|
||||
# Indrajit Raychaudhuri <irc@indrajit.com>
|
||||
#
|
||||
|
||||
# Possible lookup locations.
|
||||
@@ -36,30 +37,3 @@ elif (( $+commands[brew] )) \
|
||||
elif (( ! $+commands[node] )); then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Load NPM and known helper completions.
|
||||
typeset -A _compl_commands=(
|
||||
npm 'npm completion'
|
||||
grunt 'grunt --completion=zsh'
|
||||
gulp 'gulp --completion=zsh'
|
||||
)
|
||||
|
||||
for _compl_command in "${(k)_compl_commands[@]}"; do
|
||||
if (( $+commands[$_compl_command] )); then
|
||||
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/${_compl_command}-cache.zsh"
|
||||
|
||||
# Completion commands are slow; cache their output if old or missing.
|
||||
if [[ "$commands[$_compl_command]" -nt "$cache_file" \
|
||||
|| "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \
|
||||
|| ! -s "$cache_file" ]]; then
|
||||
mkdir -p "$cache_file:h"
|
||||
command ${=_compl_commands[$_compl_command]} >! "$cache_file" 2> /dev/null
|
||||
fi
|
||||
|
||||
source "$cache_file"
|
||||
|
||||
unset cache_file
|
||||
fi
|
||||
done
|
||||
|
||||
unset _compl_command{s,}
|
||||
|
Reference in New Issue
Block a user