Skip to content

Commit 2859489

Browse files
committed
reorder sections to group completion related changes
1 parent 1b6179a commit 2859489

File tree

1 file changed

+122
-123
lines changed

1 file changed

+122
-123
lines changed

blog/2025-10-14-nushell_v0_108_0.md

Lines changed: 122 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,120 @@ The following commands now have suggestions:
419419
- `table --theme <...>`
420420
- `split list --split <...>`
421421

422+
### Simple syntax for simple completions ([#16789])
423+
424+
Custom completions are powerful, able to provide dynamic completions based on what's written on the command line so far.
425+
426+
But you don't always need that power. In fact, for most cases a simple static list of options is enough.
427+
428+
To make it simpler and more concise to meet this need, this release adds a new way to define completions for command parameters:
429+
```ansi:no-line-numbers
430+
def go [
431+
direction: string@[ left up right down ]
432+
] {
433+
$direction
434+
}
435+
```
436+
437+
Completions can be provided as a list of strings inline in the command signature, or stored in a `const` variable and used like that.
438+
```ansi:no-line-numbers
439+
const directions = [ left up right down ]
440+
441+
def go [ direction: string@$directions ] {
442+
$direction
443+
}
444+
```
445+
446+
### Command-wide completion handler ([#16765])
447+
448+
There is big difference between custom completions that can be specified in a command's signature, and the "global" external completer (`$env.config.completions.external.completer`).
449+
450+
The former is added to individual parameters, while the latter provides completions for all arguments of (external) commands.
451+
452+
This makes using custom commands that wrap external commands awkward. The global external completer won't provide completions for the wrapper command and adding completions to that command uses a completely different API. It would be nice to be able to use the external completer's API for custom completions, or use the external completer for wrapper commands...
453+
454+
#### `@complete external`
455+
456+
Now it's possible to explicitly enable the global external completer for `extern` and custom command `def`initions:
457+
458+
```nushell
459+
@complete external
460+
def --wrapped jc [...args] {
461+
^jc ...$args | from json
462+
}
463+
```
464+
465+
#### `@complete <completer>`
466+
467+
Instead of using the external completer, command-wide custom completers can be used for specific commands:
468+
469+
```nushell
470+
def carapace-completer [spans: list<string>] {
471+
^carapace ..
472+
}
473+
474+
@complete carapace-completer
475+
def --env get-env [name] { $env | get $name }
476+
477+
@complete carapace-completer
478+
def --env set-env [name, value] { load-env { $name: $value } }
479+
480+
@complete carapace-completer
481+
def --env unset-env [name] { hide-env $name }
482+
```
483+
484+
Combined with `extern` definitions, this makes it trivial to use specific completion sources for specific commands:
485+
486+
```nushell
487+
def fish-completer [spans: list<string>] {
488+
^fish ..
489+
}
490+
491+
@complete fish-completer
492+
extern git []
493+
494+
@complete fish-completer
495+
extern asdf []
496+
```
497+
498+
Yes, you can remove the `match` expression from your external completer!
499+
500+
```nushell
501+
{|spans: list<string>|
502+
503+
# ...
504+
505+
# no need for this anymore!
506+
match $spans.0 {
507+
# fish completes commits and branch names in a nicer way
508+
git => $fish_completer
509+
# carapace doesn't have completions for asdf
510+
asdf => $fish_completer
511+
_ => $carapace_completer
512+
} | do $in $spans
513+
```
514+
515+
<details>
516+
<summary>Full implementation of <code>fish-completer</code> from the cookbook.</summary>
517+
518+
```nushell
519+
def fish-completer [spans: list<string>] {
520+
^fish --command $"complete '--do-complete=($spans | str replace --all "'" "\\'" | str join ' ')'"
521+
| from tsv --flexible --noheaders --no-infer
522+
| rename value description
523+
| update value {|row|
524+
let value = $row.value
525+
let need_quote = ['\' ',' '[' ']' '(' ')' ' ' '\t' "'" '"' "`"] | any { $in in $value }
526+
if ($need_quote and ($value | path exists)) {
527+
let expanded_path = if ($value starts-with ~) { $value | path expand --no-symlink } else { $value }
528+
$'"($expanded_path | str replace --all "\"" "\\\"")"'
529+
} else { $value }
530+
}
531+
}
532+
```
533+
534+
</details>
535+
422536
### Add `$nu.is-lsp` to help with printing in lsp mode ([#16635])
423537
When nushell is launched with the `--lsp` flag, nushell will set `$nu.is-lsp` to true so that users can programmatically know when nushell is in LSP mode.
424538

@@ -594,31 +708,6 @@ The `str length` command now has a `--chars` flag to allow you to count characte
594708
5
595709
```
596710

597-
### Simple syntax for simple completions ([#16789])
598-
599-
Custom completions are powerful, able to provide dynamic completions based on what's written on the command line so far.
600-
601-
But you don't always need that power. In fact, for most cases a simple static list of options is enough.
602-
603-
To make it simpler and more concise to meet this need, this release adds a new way to define completions for command parameters:
604-
```ansi:no-line-numbers
605-
def go [
606-
direction: string@[ left up right down ]
607-
] {
608-
$direction
609-
}
610-
```
611-
612-
Completions can be provided as a list of strings inline in the command signature, or stored in a `const` variable and used like that.
613-
```ansi:no-line-numbers
614-
const directions = [ left up right down ]
615-
616-
def go [ direction: string@$directions ] {
617-
$direction
618-
}
619-
```
620-
621-
622711
### Streams of Streams ([#16735])
623712

624713
When you run `each` over a list (or stream), it can only return a single item for each input. When we need to create multiple values from a single input, we can just return a list in the closure and run the output through `flatten`.
@@ -682,96 +771,6 @@ def slow-source [range: range] {
682771
</tbody>
683772
</table>
684773

685-
### Command-wide completion handler ([#16765])
686-
687-
There is big difference between custom completions that can be specified in a command's signature, and the "global" external completer (`$env.config.completions.external.completer`).
688-
689-
The former is added to individual parameters, while the latter provides completions for all arguments of (external) commands.
690-
691-
This makes using custom commands that wrap external commands awkward. The global external completer won't provide completions for the wrapper command and adding completions to that command uses a completely different API. It would be nice to be able to use the external completer's API for custom completions, or use the external completer for wrapper commands...
692-
693-
#### `@complete external`
694-
695-
Now it's possible to explicitly enable the global external completer for `extern` and custom command `def`initions:
696-
697-
```nushell
698-
@complete external
699-
def --wrapped jc [...args] {
700-
^jc ...$args | from json
701-
}
702-
```
703-
704-
#### `@complete <completer>`
705-
706-
Instead of using the external completer, command-wide custom completers can be used for specific commands:
707-
708-
```nushell
709-
def carapace-completer [spans: list<string>] {
710-
^carapace ..
711-
}
712-
713-
@complete carapace-completer
714-
def --env get-env [name] { $env | get $name }
715-
716-
@complete carapace-completer
717-
def --env set-env [name, value] { load-env { $name: $value } }
718-
719-
@complete carapace-completer
720-
def --env unset-env [name] { hide-env $name }
721-
```
722-
723-
Combined with `extern` definitions, this makes it trivial to use specific completion sources for specific commands:
724-
725-
```nushell
726-
def fish-completer [spans: list<string>] {
727-
^fish ..
728-
}
729-
730-
@complete fish-completer
731-
extern git []
732-
733-
@complete fish-completer
734-
extern asdf []
735-
```
736-
737-
Yes, you can remove the `match` expression from your external completer!
738-
739-
```nushell
740-
{|spans: list<string>|
741-
742-
# ...
743-
744-
# no need for this anymore!
745-
match $spans.0 {
746-
# fish completes commits and branch names in a nicer way
747-
git => $fish_completer
748-
# carapace doesn't have completions for asdf
749-
asdf => $fish_completer
750-
_ => $carapace_completer
751-
} | do $in $spans
752-
```
753-
754-
<details>
755-
<summary>Full implementation of <code>fish-completer</code> from the cookbook.</summary>
756-
757-
```nushell
758-
def fish-completer [spans: list<string>] {
759-
^fish --command $"complete '--do-complete=($spans | str replace --all "'" "\\'" | str join ' ')'"
760-
| from tsv --flexible --noheaders --no-infer
761-
| rename value description
762-
| update value {|row|
763-
let value = $row.value
764-
let need_quote = ['\' ',' '[' ']' '(' ')' ' ' '\t' "'" '"' "`"] | any { $in in $value }
765-
if ($need_quote and ($value | path exists)) {
766-
let expanded_path = if ($value starts-with ~) { $value | path expand --no-symlink } else { $value }
767-
$'"($expanded_path | str replace --all "\"" "\\\"")"'
768-
} else { $value }
769-
}
770-
}
771-
```
772-
773-
</details>
774-
775774
### The `to md` command now always returns valid Markdown tables ([#16681])
776775
Previously, a command like this:
777776
```shell
@@ -922,6 +921,14 @@ Error: nu::parser::invalid_binary_string
922921

923922
## Bug fixes
924923

924+
### Aliases are now expanded before being sent to external completers ([#16640])
925+
926+
Before this change, when an external completer was invoked for an alias, the first argument sent to the completer would be the alias itself instead of the aliased command.
927+
928+
For example, with an alias defined as `alias gl = git log`, typing `gl branch_name` and pressing `TAB` would send the arguments `gl`, `log`, `branch_name` to the external completer.
929+
930+
After this change, the alias is expanded and the arguments sent to the external completer will be `git`, `log`, `branch_name`.
931+
925932
### Discard `path add` input ([#16606])
926933
Previously `path add` (from `std/util`) could fail if it was fed `any` input.
927934
```ansi:no-line-numbers
@@ -946,14 +953,6 @@ Now any input to `path add` will be discarded. It's still possible to pass it wi
946953
[a b c] | each {|p| $env.HOME | path join $p } | path add $in
947954
```
948955

949-
### Aliases are now expanded before being sent to external completers ([#16640])
950-
951-
Before this change, when an external completer was invoked for an alias, the first argument sent to the completer would be the alias itself instead of the aliased command.
952-
953-
For example, with an alias defined as `alias gl = git log`, typing `gl branch_name` and pressing `TAB` would send the arguments `gl`, `log`, `branch_name` to the external completer.
954-
955-
After this change, the alias is expanded and the arguments sent to the external completer will be `git`, `log`, `branch_name`.
956-
957956
### Fixed IR evaluation error caused by redirecting output of branched blocks ([#16676])
958957

959958
The following commands will no longer raise ir-eval errors:

0 commit comments

Comments
 (0)