Skip to content

Commit 0e54eef

Browse files
blindFSysthakur
andauthored
Move zoxide completer from external_completers to custom_completions (#1847)
* remove zoxide completer from external_completers.md * Add zoxide completer to custom_completions.md * Update book/custom_completions.md Co-authored-by: Yash Thakur <[email protected]> --------- Co-authored-by: Yash Thakur <[email protected]>
1 parent 6b6f2aa commit 0e54eef

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

book/custom_completions.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ cat rat bat
6969

7070
Because we made matching case-insensitive, Nushell will find the substring "a" in all of the completion suggestions. Additionally, because we set `sort: false`, the completions will be left in their original order. This is useful if your completions are already sorted in a particular order unrelated to their text (e.g. by date).
7171

72+
## Another Practical Example - Zoxide Path Completions
73+
74+
[Zoxide](https://github.com/ajeetdsouza/zoxide) allows easily jumping between visited folders in the system. It's possible to autocomplete matching folders with this completer:
75+
76+
```nu
77+
def "nu-complete zoxide path" [context: string] {
78+
let parts = $context | split row " " | skip 1
79+
{
80+
options: {
81+
sort: false,
82+
completion_algorithm: prefix,
83+
positional: false,
84+
case_sensitive: false,
85+
},
86+
completions: (zoxide query --list --exclude $env.PWD -- ...$parts | lines),
87+
}
88+
}
89+
90+
def --env --wrapped z [...rest: string@"nu-complete zoxide path"] {
91+
__zoxide_z ...$rest
92+
}
93+
```
94+
7295
## Modules and Custom Completions
7396

7497
Since completion commands aren't meant to be called directly, it's common to define them in modules.
@@ -228,4 +251,4 @@ let carapace_completer = {|spans|
228251
}
229252
```
230253

231-
[More examples of custom completers can be found in the cookbook](../cookbook/external_completers.md).
254+
[More examples of external completers can be found in the cookbook](../cookbook/external_completers.md).

cookbook/external_completers.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,6 @@ A couple of things to note on this command:
3636
- `--no-infer` is optional. `from tsv` will infer the data type of the result, so a numeric value like some git hashes will be inferred as a number. `--no-infer` will keep everything as a string. It doesn't make a difference in practice but it will print a more consistent output if the completer is ran on it's own.
3737
- Since fish only supports POSIX style escapes for file paths (`file\ name.txt`, etc.), file paths completed by fish will not be quoted or escaped properly on external commands. Nushell does not parse POSIX escapes, so we need to do this conversion manually such as by testing if the items are valid paths as shown in the example. This simple approach is imperfect, but it should cover 99.9% of use cases.
3838

39-
### Zoxide completer
40-
41-
[Zoxide](https://github.com/ajeetdsouza/zoxide) allows easily jumping between visited folders in the system. It's possible to autocomplete matching folders with this completer:
42-
43-
```nu
44-
let zoxide_completer = {|spans|
45-
$spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD}
46-
}
47-
```
48-
49-
This completer is not usable for almost every other command, so it's recommended to add it as an override in the [multiple completer](#multiple-completer):
50-
51-
```nu
52-
{
53-
z => $zoxide_completer
54-
zi => $zoxide_completer
55-
}
56-
```
57-
58-
> **Note**
59-
> Zoxide sets an alias (`z` by default) that calls the `__zoxide_z` function.
60-
> If [alias completions](#alias-completions) are supported, the following snippet can be used instead:
61-
>
62-
> ```nu
63-
> {
64-
> __zoxide_z => $zoxide_completer
65-
> __zoxide_zi => $zoxide_completer
66-
> }
67-
> ```
68-
6939
### Multiple completer
7040

7141
Sometimes, a single external completer is not flexible enough. Luckily, as many as needed can be combined into a single one. The following example uses `$default_completer` for all commands except the ones explicitly defined in the record:
@@ -158,8 +128,6 @@ let external_completer = {|spans|
158128
git => $fish_completer
159129
# carapace doesn't have completions for asdf
160130
asdf => $fish_completer
161-
# use zoxide completions for zoxide commands
162-
__zoxide_z | __zoxide_zi => $zoxide_completer
163131
_ => $carapace_completer
164132
} | do $in $spans
165133
}

0 commit comments

Comments
 (0)