diff --git a/cmd/carapace/cmd/lazyInit.go b/cmd/carapace/cmd/lazyInit.go index fd7c6cda96..499d4647c0 100644 --- a/cmd/carapace/cmd/lazyInit.go +++ b/cmd/carapace/cmd/lazyInit.go @@ -56,11 +56,26 @@ complete -c '%v' -f -a '(_carapace_lazy %v)'`, completer, completer, completer) } func nushell_lazy(completers []string) string { - snippet := make([]string, len(completers)) + exports := make([]string, len(completers)) for index, completer := range completers { - snippet[index] = fmt.Sprintf(`config set completion.%v [carapace %v nushell _]`, completer, completer) + exports[index] = fmt.Sprintf(` export extern "%v" [ + ...args: string@"nu-complete carapace" + ]`, completer) } - return strings.Join(snippet, "\n") + return fmt.Sprintf(`module carapace { + def "nu-complete carapace" [line: string, pos: int] { + let words = ($line | str substring [0 $pos] | split row " ") + if ($line | str substring [0 $pos] | str ends-with " ") { + carapace $words.0 nushell ($words | append "") | from json + } else { + carapace $words.0 nushell $words | from json + } + } + +%v +} +use carapace * +`, strings.Join(exports, "\n")) } func oil_lazy(completers []string) string { diff --git a/go.mod b/go.mod index ddfca6e894..6ce706754d 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-ps v1.0.0 github.com/pelletier/go-toml v1.9.5 - github.com/rsteube/carapace v0.19.5 + github.com/rsteube/carapace v0.19.6 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 golang.org/x/sys v0.0.0-20211205182925-97ca703d548d diff --git a/go.sum b/go.sum index 7dce6fda48..ef343e15e8 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rsteube/carapace v0.19.5 h1:VPrHbswk0KucIE+kS7CjPCRciqQO0Ham09XGWIYU+L8= -github.com/rsteube/carapace v0.19.5/go.mod h1:GgiwpPVhucHNOv0AmtIkxhiEFkCMP5BBRauyQLP0mFY= +github.com/rsteube/carapace v0.19.6 h1:8J+Ln3lzccYnJRGzPPvFGtdZRlYiL2qZ2NhbEgP46DU= +github.com/rsteube/carapace v0.19.6/go.mod h1:GgiwpPVhucHNOv0AmtIkxhiEFkCMP5BBRauyQLP0mFY= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=