SuperAPI AI 工具集

dotnet-enable-autocomplete

通用与其它

查看项目

更新于 10-16 06:17

技能介绍

用途:为 dotnet CLI 配置 shell 的 Tab 自动补全,适用于希望补全 dotnet 命令与参数的用户。

主要能力:先运行 dotnet sdk check 判断已安装 SDK 版本,因为命令随版本不同。.NET 10+ 使用原生 dotnet completions script <shell>;.NET 10 之前使用 dotnet complete --position 的动态补全脚本。支持 PowerShell、bash、zsh、fish、nushell 多选。

使用方式:按 shell 定位配置文件(PowerShell 为 $PROFILE,bash 为 ~/.bashrc,zsh 为 ~/.zshrc,fish 为 ~/.config/fish/config.fish,nushell 为 ~/.config/nushell/config.nu),先读取并检查是否已存在 dotnet 补全配置,若存在则询问是否替换,再将补全脚本追加到配置文件,最后提示用户重启 shell 或 source 配置文件。

.NET 10+ 示例:PowerShell 用 dotnet completions script pwsh | Out-String | Invoke-Expression;bash 用 eval "$(dotnet completions script bash)";zsh 用 eval "$(dotnet completions script zsh)";fish 用 dotnet completions script fish | source;nushell 需参考 .NET CLI 文档配置 config.nu。

旧版示例:PowerShell 用 Register-ArgumentCompleter 注册 dotnet complete;bash 用 complete -f -F _dotnet_bash_complete dotnet;zsh 用 compctl -K _dotnet_zsh_complete dotnet;fish 用 complete -f -c dotnet -a "(dotnet complete ...)";nushell 在 config.nu 的 external_completer 中处理。

限制与注意:若 dotnet sdk check 失败需先安装 .NET SDK;配置文件不存在则创建,只读则提示手动添加;修改前应备份配置文件;更改需重启 shell 或 source 后生效。nushell 在 .NET 10+ 的原生补全配置资料未完整给出。