Skip to content

Commit 549f07a

Browse files
committed
added jj
1 parent 20179e4 commit 549f07a

4 files changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Supported inputs:
2222
- [fish](https://fishshell.com/)
2323
- [gcloud](https://docs.cloud.google.com/sdk/gcloud)
2424
- [inshellisense](https://github.com/microsoft/inshellisense)
25+
- [jj](https://www.jj-vcs.dev)
2526
- [kingpin](https://github.com/alecthomas/kingpin)
2627
- [kitten](https://github.com/kovidgoyal/kitty)
2728
- [powershell](https://microsoft.com/powershell)

cmd/carapace-bridge/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func init() {
5353
addSubCommand("fish", "bridges completions registered in fish", bridge.ActionFish)
5454
addSubCommand("gcloud", "bridges https://docs.cloud.google.com/sdk/gcloud", bridge.ActionGcloud)
5555
addSubCommand("inshellisense", "bridges https://github.com/microsoft/inshellisense", bridge.ActionInshellisense)
56+
addSubCommand("jj", "bridges https://www.jj-vcs.dev", bridge.ActionJJ)
5657
addSubCommand("kingpin", "bridges https://github.com/alecthomas/kingpin", bridge.ActionKingpin)
5758
addSubCommand("kitten", "bridges https://github.com/kovidgoyal/kitty", bridge.ActionKitten)
5859
addSubCommand("macro", "bridges macros exposed with https://github.com/carapace-sh/carapace-spec", bridge.ActionMacro)

pkg/actions/bridge/bridge.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var bridgeActions = map[string]func(command ...string) carapace.Action{
2525
"fish": ActionFish,
2626
"gcloud": ActionGcloud,
2727
"inshellisense": ActionInshellisense,
28+
"jj": ActionJJ,
2829
"kingpin": ActionKingpin,
2930
"kitten": ActionKitten,
3031
"powershell": ActionPowershell,
@@ -68,6 +69,7 @@ func ActionBridges(name string) carapace.Action {
6869
"fish", "bridges completions registered in fish",
6970
"gcloud", "bridges https://docs.cloud.google.com/sdk/gcloud",
7071
"inshellisense", "bridges https://github.com/microsoft/inshellisense",
72+
"jj", "bridges bridges https://www.jj-vcs.dev",
7173
"kitten", "bridges https://github.com/kovidgoyal/kitty",
7274
"powershell", "bridges completions registered in powershell",
7375
"zsh", "bridges completions registered in zsh",
@@ -78,6 +80,7 @@ func ActionBridges(name string) carapace.Action {
7880
"carapace-bin": "carapace",
7981
"fish": "fish",
8082
"gcloud": "gcloud",
83+
"jj": "jj",
8184
"inshellisense": "inshellisense",
8285
"kitten": "kitten",
8386
"powershell": "pwsh",

pkg/actions/bridge/jj.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package bridge
2+
3+
import (
4+
"strings"
5+
6+
"github.com/carapace-sh/carapace"
7+
)
8+
9+
// ActionJJ bridges https://www.jj-vcs.dev
10+
func ActionJJ(command ...string) carapace.Action {
11+
return actionCommand(command...)(func(command ...string) carapace.Action {
12+
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
13+
c.Setenv("COMPLETE", "fish")
14+
args := []string{"--"}
15+
args = append(args, command...)
16+
args = append(args, c.Args...)
17+
args = append(args, c.Value)
18+
return carapace.ActionExecCommand(command[0], args...)(func(output []byte) carapace.Action {
19+
lines := strings.Split(string(output), "\n")
20+
vals := make([]string, 0)
21+
22+
flags := strings.HasPrefix(c.Value, "-")
23+
for _, line := range lines[:len(lines)-1] {
24+
value, description, _ := strings.Cut(line, "\t")
25+
if flags == strings.HasPrefix(value, "-") {
26+
vals = append(vals, value, description)
27+
}
28+
}
29+
return carapace.ActionValuesDescribed(vals...)
30+
}).Invoke(c).ToA()
31+
})
32+
})
33+
}

0 commit comments

Comments
 (0)