NuShell命令补全 —— Carapace e.g
Intro
Carapace是一个多 shell 补全库,对 git,docker,ssh 等常用工具有很好的支持,此外支持多种 shell,包括 bash、zsh、fish、nushell 等。类似的工具还有inshellisense,但 inshellisense 似乎与 ohmyposh 存在兼容问题。
Nushell是一个现代的 shell,支持 win,linux,mac,Windows,WSL,Linux 下共享一套配置十分方便。目前维护了五年多,更新频繁,社区活跃。
Carapace | Nushell |
---|---|
![]() | ![]() |
Completers
Nushell 的补全主要有两种方案:
- Custom Completion
- 针对部分命令,未必有 External Completer 适配,例如 vscode,scoop。此时可在 Nushell 社区搜索相应的的 Completion Script,或自行编写
- External Completers
- Zoxide completer
- Fish completer
- Carapace completer
Setup
Config
- 下载
zoxide
,carapace
- 添加如下 config 即可
- 根据需求设置 menu,keybindings 等,个人配置<github.com/Efterklang/config>,相关 blog👉terminal
NUSHELL
completions.nu
let carapace_completer = {|spans| carapace $spans.0 nushell ...$spans | from json}let zoxide_completer = {|spans| $spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD}}let multiple_completers = {|spans| match $spans.0 { z => $zoxide_completer _ => $carapace_completer } | do $in $spans}$env.config.completions = { case_sensitive: true # set to true to enable case-sensitive completions quick: true # set this to false to prevent auto-selecting completions when only one remains partial: true # set this to false to prevent partial filling of the prompt algorithm: "prefix" # prefix or fuzzy external: { enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up may be very slow max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options completer: $multiple_completers } use_ls_colors: true}
在config.nu
中添加如下代码
NUSHELL
config.nu
source ./completions/completions.nu [!code ++]
Demo
一个简单的例子,输入ssh
后,按tab
键,会自动补全可连接的 remote machine;输入git switch
后,按tab
键会补全可选择的分支。

NuShell命令补全 —— Carapace e.g