mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-06-26 05:21:17 +02:00
npm: update with simpler logic
This commit is contained in:
parent
7b3954dda7
commit
69676a874f
1 changed files with 4 additions and 36 deletions
|
|
@ -1,44 +1,12 @@
|
||||||
(( $+commands[npm] )) && {
|
(( $+commands[npm] )) && {
|
||||||
|
__NPM_COMPLETION_FILE="${ZSH_CACHE_DIR:-$ZSH/cache}/npm_completion"
|
||||||
# Check if ZSH_CACHE_DIR is set.
|
|
||||||
# If not, proceeds to find any existing directories containing npm_completion.
|
|
||||||
# If can't find any, defaults to ZSH_CACHE_DEFAULT_DIR and sets ZSH_CACHE_DIR accordingly.
|
|
||||||
if [ !${ZSH_CACHE_DIR} ]; then
|
|
||||||
|
|
||||||
# Default cache directory in case none was found containing npm_completion file.
|
|
||||||
ZSH_CACHE_DEFAULT_DIR="${HOME}/.oh-my-zsh/cache"
|
|
||||||
|
|
||||||
# List of directories to look for npm_completion file.
|
if [[ ! -f $__NPM_COMPLETION_FILE ]]; then
|
||||||
ZSH_CACHE_POSSIBLE_DIR=(
|
|
||||||
"${HOME}/.oh-my-zsh/cache"
|
|
||||||
"${HOME}/.zsh/cache"
|
|
||||||
"${HOME}/.antigen/bundles/robbyrussell/oh-my-zsh/cache"
|
|
||||||
"${HOME}/.tmp/cache"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Loop list of possible cache directories containing npm_completion file
|
|
||||||
# and set ZSH_CACHE_DIR to the first found.
|
|
||||||
for d in "${ZSH_CACHE_POSSIBLE_DIR[@]}"; do
|
|
||||||
# Exits loop if previous iteration already found an existing ${d}/npm_completion
|
|
||||||
# & already set ZSH_CACHE_DIR to ${d}.
|
|
||||||
[ ${ZSH_CACHE_DIR} ] && break
|
|
||||||
|
|
||||||
# If current exists then sets ZSH_CACHE_DIR to it
|
|
||||||
[ -f "${d}/npm_completion" ] && ZSH_CACHE_DIR=${d}
|
|
||||||
done
|
|
||||||
|
|
||||||
# If ZSH_CACHE_DIR still not set, then set to ZSH_CACHE_DEFAULT_DIR.
|
|
||||||
[ -z ${ZSH_CACHE_DIR} ] && ZSH_CACHE_DIR=${ZSH_CACHE_DEFAULT_DIR}
|
|
||||||
fi
|
|
||||||
|
|
||||||
__NPM_COMPLETION_FILE="${ZSH_CACHE_DIR}/npm_completion"
|
|
||||||
|
|
||||||
if [ ! -f $__NPM_COMPLETION_FILE ]; then
|
|
||||||
npm completion >! $__NPM_COMPLETION_FILE 2>/dev/null
|
npm completion >! $__NPM_COMPLETION_FILE 2>/dev/null
|
||||||
[ $? -ne 0 ] && rm -f $__NPM_COMPLETION_FILE
|
[[ $? -ne 0 ]] && rm -f $__NPM_COMPLETION_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ -f $__NPM_COMPLETION_FILE ] && source $__NPM_COMPLETION_FILE
|
[[ -f $__NPM_COMPLETION_FILE ]] && source $__NPM_COMPLETION_FILE
|
||||||
|
|
||||||
unset __NPM_COMPLETION_FILE
|
unset __NPM_COMPLETION_FILE
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue