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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File: ./completions/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
中添加如下代码
1
2
# File: ./config.nu
+ source ./completions/completions.nu
Demo
一个简单的例子,输入ssh
后,按tab
键,会自动补全可连接的remote machine;输入git switch
后,按tab
键会补全可选择的分支。

NuShell命令补全 —— Carapace e.g