Skip to content

Commit 92ad34a

Browse files
committed
nushell: adopt alias expansion from carapace-bin
1 parent bedfad9 commit 92ad34a

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

example/cmd/_test/nushell.nu

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
let example_completer = {|spans|
1+
let example_completer = {|spans|
2+
# if the current command is an alias, get it's expansion
3+
let expanded_alias = (scope aliases | where name == $spans.0 | $in.0?.expansion?)
4+
5+
# overwrite
6+
let spans = (if $expanded_alias != null {
7+
# put the first word of the expanded alias first in the span
8+
$spans | skip 1 | prepend ($expanded_alias | split row " " | take 1)
9+
} else {
10+
$spans | skip 1 | prepend ($spans.0)
11+
})
12+
213
example _carapace nushell ...$spans | from json
314
}

internal/shell/nushell/snippet.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@ import (
1010

1111
// Snippet creates the nushell completion script.
1212
func Snippet(cmd *cobra.Command) string {
13-
return fmt.Sprintf(`let %v_completer = {|spans|
13+
return fmt.Sprintf(`let %v_completer = {|spans|
14+
# if the current command is an alias, get it's expansion
15+
let expanded_alias = (scope aliases | where name == $spans.0 | $in.0?.expansion?)
16+
17+
# overwrite
18+
let spans = (if $expanded_alias != null {
19+
# put the first word of the expanded alias first in the span
20+
$spans | skip 1 | prepend ($expanded_alias | split row " " | take 1)
21+
} else {
22+
$spans | skip 1 | prepend ($spans.0)
23+
})
24+
1425
%v _carapace nushell ...$spans | from json
1526
}`, cmd.Name(), uid.Executable())
1627
}

0 commit comments

Comments
 (0)