配置标签补全
从 5.34.0 版本开始,Rush 支持标签补全,以便可以通过按 TAB 键更快速地输入 shell 命令。以下设置说明基于文章 .NET Core CLI 的标签补全,其中提供了一些额外的技巧。
PowerShell
要为 PowerShell 启用标签补全,请创建或编辑存储在 $PROFILE
变量中的配置文件。有关更多信息,请参阅 如何创建配置文件 和 配置文件和执行策略。
将以下代码添加到配置文件中
# PowerShell parameter completion shim for the Rush CLI
Register-ArgumentCompleter -Native -CommandName rush -ScriptBlock {
param($commandName, $commandAst, $cursorPosition)
[string]$value = $commandAst.ToString()
# Handle input like `rush install; rush bui` + Tab
[int]$position = [Math]::Min($cursorPosition, $value.Length)
rush tab-complete --position $position --word "$value" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Bash
要为 Bash 启用标签补全,请将以下代码添加到 .bashrc 文件中
# bash parameter completion for the Rush CLI
_rush_bash_complete()
{
local word=${COMP_WORDS[COMP_CWORD]}
local completions
completions="$(rush tab-complete --position "${COMP_POINT}" --word "${COMP_LINE}" 2>/dev/null)"
if [ $? -ne 0 ]; then
completions=""
fi
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}
complete -f -F _rush_bash_complete rush
Fish
要为 Fish shell 启用标签补全,请将以下代码添加到文件 ~/.config/fish/completions/rush.fish 中
# Fish parameter completions for the Rush CLI
complete rush --no-files
function __fish_rush
set -l position (string length (commandline -cp))
set -l word (commandline -opc)
rush tab-complete --word "$word" --position "$position"
end
complete rush -x -a "(__fish_rush)"
Zsh
Zsh 具有略微不同的环境变量,请将以下内容添加到 ~/.zshrc 中
(( ${+commands[rush]} )) && {
_rush_completion() {
compadd -- $(rush tab-complete --position ${CURSOR} --word "${BUFFER}" 2>>/dev/null)
}
compdef _rush_completion rush
}
它检查 rush 的存在。这需要在 PATH 设置好后(或在 nvm 初始化后)添加。否则,您需要删除第一行。