Skip to content

Commit

Permalink
support cmd-clink
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Dec 29, 2024
1 parent 37a24ba commit e44a95c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
33 changes: 33 additions & 0 deletions cmd/carapace/cmd/lazyinit/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package lazyinit

import (
"fmt"
"strings"
)

func CmdClink(completers []string) string {
// TODO pathSnippet
snippet := `local function carapace_completion(command)
return function(word, word_index, line_state, match_builder)
local compline = string.sub(line_state:getline(), 1, line_state:getcursor())
local prog = string.format("env CARAPACE_COMPLINE=%%s carapace %%s cmd-clink '' ''", string.format("%%q", compline), command)
local output = io.popen(prog):read("*a")
for line in string.gmatch(output, '[^\r\n]+') do
match_builder:addmatch(string.gsub(line, '\t.*', ""))
end
return true
end
end
%v
`
argmatchers := make([]string, 0, len(completers))
for _, completer := range completers {
argmatchers = append(argmatchers,
fmt.Sprintf(`clink.argmatcher("%v"):addarg({carapace_completion("%v")}):loop(1)`, completer, completer),
fmt.Sprintf(`clink.argmatcher("%v.exe"):addarg({carapace_completion("%v")}):loop(1)`, completer, completer),
)
}
return fmt.Sprintf(snippet, strings.Join(argmatchers, "\n"))
}
2 changes: 2 additions & 0 deletions cmd/carapace/cmd/lazyinit/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func Snippet(shell string) string {
return Bash(completerNames)
case "bash-ble":
return BashBle(completerNames)
case "cmd-clink":
return CmdClink(completerNames)
case "elvish":
return Elvish(completerNames)
case "fish":
Expand Down
1 change: 1 addition & 0 deletions cmd/carapace/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func Execute(version string) error {
switch shell {
case "bash",
"bash-ble",
"cmd-clink",
"elvish",
"fish",
"nushell",
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ require (
)

replace github.com/spf13/pflag => github.com/carapace-sh/carapace-pflag v1.0.0

replace github.com/carapace-sh/carapace => github.com/carapace-sh/carapace v1.5.3-0.20241229192213-225be410a233
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/carapace-sh/carapace v1.5.2 h1:ddFLVzPLmEUnKTtglMDDnfbFSYyCMEd0xn1ysguSWLw=
github.com/carapace-sh/carapace v1.5.2/go.mod h1:djegtVDi/3duSAqZNU+/nCq7XtDRMRZUb5bW0O/HnEs=
github.com/carapace-sh/carapace v1.5.3-0.20241229192213-225be410a233 h1:cceMGeKF831Wo8Jnr4fPFjU1PCmFaOBquMZDtF6vCqc=
github.com/carapace-sh/carapace v1.5.3-0.20241229192213-225be410a233/go.mod h1:0EJBqcIPrDiZ7+QMKPd0/LhJz3inAvdTz8JfLnH7SsU=
github.com/carapace-sh/carapace-bridge v1.2.2 h1:Zlzw7BajF4iHAFBClCYcptEG+7+F324dFyiGzGiU/kw=
github.com/carapace-sh/carapace-bridge v1.2.2/go.mod h1:HpN3iEdCmQtAD1pd/qHEnWmAF719CeNyJrY8FJ5/E4o=
github.com/carapace-sh/carapace-pflag v1.0.0 h1:uJMhl+vwEM/Eb0UdxZUuv4jo4rUAyPijkRGP5gfCuCE=
Expand Down

0 comments on commit e44a95c

Please sign in to comment.