Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support cmd-clink #2666

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
44 changes: 44 additions & 0 deletions cmd/carapace/cmd/lazyinit/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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
local matches = {}
for m in string.gmatch(line, '[^\t]+') do
table.insert(matches, m)
end
match_builder:addmatch({
match = matches[1],
display = matches[2],
description = matches[3],
type = "word",
appendchar = matches[4],
suppressappend = false
})
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({nowordbreakchars="'‵+;,", carapace_completion("%v")}):loop(1)`, completer, completer),
fmt.Sprintf(`clink.argmatcher("%v.exe"):addarg({nowordbreakchars="'‵+;,", 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: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/carapace-sh/carapace-bin
go 1.23.1

require (
github.com/carapace-sh/carapace v1.5.2
github.com/carapace-sh/carapace v1.5.3-0.20241231194352-a81180bbc1a0
github.com/carapace-sh/carapace-bridge v1.2.2
github.com/carapace-sh/carapace-selfupdate v0.0.8
github.com/carapace-sh/carapace-shlex v1.0.1
Expand Down
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.20241231194352-a81180bbc1a0 h1:ME/jL2px+lnwY3vPTrZOCn0X4h2KSqSD7yB0Lh0GRPU=
github.com/carapace-sh/carapace v1.5.3-0.20241231194352-a81180bbc1a0/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
19 changes: 19 additions & 0 deletions pkg/actions/env/carapace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/cmd/carapace/cmd/action"
"github.com/carapace-sh/carapace-bin/pkg/env"
"github.com/carapace-sh/carapace-bridge/pkg/actions/bridge"
"github.com/carapace-sh/carapace/pkg/style"
)

Expand All @@ -14,12 +15,14 @@ func init() {
Variables: map[string]string{
// carapace
"CARAPACE_COVERDIR": "coverage directory for sandbox tests",
"CARAPACE_COMPLINE": "TODO", // TODO
"CARAPACE_ENV": "register get-env, set-env and unset-env",
"CARAPACE_HIDDEN": "show hidden commands/flags",
"CARAPACE_LENIENT": "allow unknown flags",
"CARAPACE_LOG": "enable logging",
"CARAPACE_MATCH": "match case insensitive",
"CARAPACE_NOSPACE": "nospace suffixes",
"CARAPACE_SHELL": "TODO", // TODO
"CARAPACE_SANDBOX": "mock context for sandbox tests",
"CARAPACE_TOOLTIP": "enable tooltip style",
"CARAPACE_ZSH_HASH_DIRS": "zsh hash directories",
Expand All @@ -30,6 +33,7 @@ func init() {
VariableCompletion: map[string]carapace.Action{
// carapace
"CARAPACE_COVERDIR": carapace.ActionDirectories(),
"CARAPACE_COMPLINE": bridge.ActionCarapaceBin().Split(),
"CARAPACE_ENV": _bool,
"CARAPACE_HIDDEN": _bool,
"CARAPACE_LENIENT": _bool,
Expand All @@ -42,6 +46,21 @@ func init() {
"*", "match all",
).UniqueList(""),
"CARAPACE_SANDBOX": carapace.ActionValues(),
"CARAPACE_SHELL": carapace.ActionStyledValues(
"bash", "#d35673",
"bash-ble", "#c2039a",
"cmd-clink", "#2B3436",
"elvish", "#ffd6c9",
"export", style.Default,
"fish", "#7ea8fc",
"ion", "#0e5d6d",
"nushell", "#29d866",
"oil", "#373a36",
"powershell", "#e8a16f",
"tcsh", "#412f09",
"xonsh", "#a8ffa9",
"zsh", "#efda53",
),
"CARAPACE_TOOLTIP": _bool,
// carapace-bin
"CARAPACE_EXCLUDES": carapace.Batch(
Expand Down
Loading