代码拉取完成,页面将自动刷新
#!/usr/bin/env bash
# Shell completion for Deno Version Manager
# Copyright (C) 2020 ~ 2024, Chen Su and all contributors.
if ! type dvm &> /dev/null
then
return
fi
# Add available aliases into auto-completion options list.
_dvm_add_aliases_to_opts() {
if [ ! -d "$DVM_DIR/aliases" ]
then
return
fi
if [ -z "$(ls -A "$DVM_DIR/aliases")" ]
then
return 0
fi
for path in "$DVM_DIR/aliases"/*
do
alias_name=${path##*/}
version=$(cat "$path")
if [ -f "$DVM_DIR/versions/$version/deno" ]
then
opts="$opts $alias_name"
fi
done
}
# Add commands and top-level option (--help and --version) to options.
_dvm_add_command_and_top_option() {
if [[ ${cur} == -* ]]
then
opts="-h --help --version"
else
opts="alias clean current deactivate doctor help install list list-remote
ls ls-remote run upgrade unalias uninstall use which"
fi
}
# Add the specified options into the options list if no one was inputted.
_dvm_add_exclusive_option() {
if _dvm_no_option_input "${@}"
then
opts="$opts $*"
fi
}
# Add options for command install.
_dvm_add_install_option() {
_dvm_add_exclusive_option "--from-binary" "--from-source"
_dvm_add_options "--registry=" "--skip-validation"
}
# Add the specified option to the options list.
_dvm_add_options() {
for opt in "${@}"
do
if ! [[ ${COMP_WORDS[*]} =~ $opt ]]
then
opts="$opts $opt"
fi
done
}
# Add common options into auto-completion options list.
_dvm_add_options_to_opts() {
local prev
prev="$1"
if [ "$prev" == "run" ]
then
return
fi
if [[ ${cur} != -* ]]
then
return
fi
_dvm_add_exclusive_option "-q" "--quiet"
_dvm_add_exclusive_option "--color" "--no-color"
_dvm_add_options "--verbose"
}
# Add available installed versions into auto-completion options list.
_dvm_add_versions_to_opts() {
if [ ! -d "$DVM_DIR/versions" ]
then
return
fi
if [ -z "$(ls -A "$DVM_DIR/versions")" ]
then
return 0
fi
for path in "$DVM_DIR/versions"/*
do
if [ -f "$path/deno" ]
then
version=${path##*/}
opts="$opts $version"
fi
done
}
# Set auto-completion with specific command.
_dvm_completion() {
local command
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [ "$COMP_CWORD" = "1" ]
then
_dvm_add_command_and_top_option
else
command="${COMP_WORDS[1]}"
case "$command" in
"doctor")
_dvm_add_exclusive_option "--fix"
;;
"install")
if [[ ${cur} == -* ]]
then
_dvm_add_install_option
fi
;;
"use"|"uninstall"|"which")
if ! _dvm_has_non_option_parameter
then
if [ "$command" = "which" ] && _dvm_has_active_version
then
opts="current"
fi
_dvm_add_versions_to_opts
_dvm_add_aliases_to_opts
fi
;;
"run")
if _dvm_has_non_option_parameter
then
COMPREPLY=( "$(compgen -W "${opts}" -- "${cur}")" )
return
fi
_dvm_add_versions_to_opts
_dvm_add_aliases_to_opts
;;
"unalias")
if [ "$COMP_CWORD" == 2 ] || ! _dvm_has_non_option_parameter
then
_dvm_add_aliases_to_opts
fi
;;
*)
opts=""
;;
esac
_dvm_add_options_to_opts "$prev"
fi
COMPREPLY=( "$(compgen -W "${opts}" -- "${cur}")" )
}
# Check if any Deno version has been activated that installed by DVM.
_dvm_has_active_version() {
echo "$PATH" | grep -q "$DVM_DIR/versions"
}
# Checks whether the parameters list have non-option parameter or not.
_dvm_has_non_option_parameter() {
for word in "${COMP_WORDS[@]:2}"
do
if [[ "$word" != -* ]]
then
true
return
fi
done
false
}
# Check whether the specified options are inputted or not
_dvm_no_option_input() {
for opt in "${@}"
do
if [[ ${COMP_WORDS[*]} =~ $opt ]]
then
false
return
fi
done
true
}
if [ -n "$ZSH_NAME" ]
then
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
fi
complete -F _dvm_completion dvm
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。