Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion example/cmd/_test/nushell.nu
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
let example_completer = {|spans|
let example_completer = {|spans|
# if the current command is an alias, get it's expansion
let expanded_alias = (scope aliases | where name == $spans.0 | $in.0?.expansion?)

# overwrite
let spans = (if $expanded_alias != null {
# put the first word of the expanded alias first in the span
$spans | skip 1 | prepend ($expanded_alias | split row " " | take 1)
} else {
$spans | skip 1 | prepend ($spans.0)
})

example _carapace nushell ...$spans | from json
}
13 changes: 12 additions & 1 deletion internal/shell/nushell/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ import (

// Snippet creates the nushell completion script.
func Snippet(cmd *cobra.Command) string {
return fmt.Sprintf(`let %v_completer = {|spans|
return fmt.Sprintf(`let %v_completer = {|spans|
# if the current command is an alias, get it's expansion
let expanded_alias = (scope aliases | where name == $spans.0 | $in.0?.expansion?)

# overwrite
let spans = (if $expanded_alias != null {
# put the first word of the expanded alias first in the span
$spans | skip 1 | prepend ($expanded_alias | split row " " | take 1)
} else {
$spans | skip 1 | prepend ($spans.0)
})

%v _carapace nushell ...$spans | from json
}`, cmd.Name(), uid.Executable())
}