Skip to content

Commit b0ec6bb

Browse files
authored
Merge pull request #3099 from carapace-sh/jj-color
jj: always disable color when executing
2 parents a6059d3 + 26d655e commit b0ec6bb

File tree

12 files changed

+27
-16
lines changed

12 files changed

+27
-16
lines changed

pkg/actions/tools/jj/bookmark.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// master (qvlkomxp 9a2e553b (empty) Merge pull request #939 from rsteube/docker-update-...)
1515
// mdbook-linkcheck (numonpmw ad5c8efd mdbook: enable web-links)
1616
func ActionLocalBookmarks() carapace.Action {
17-
return carapace.ActionExecCommand("jj", "bookmark", "list")(func(output []byte) carapace.Action {
17+
return actionExecJJ("bookmark", "list")(func(output []byte) carapace.Action {
1818
lines := strings.Split(string(output), "\n")
1919
rLocal := regexp.MustCompile(`^(?P<bookmark>[^@: ]+): (?P<changeid>[^ ]+) (?P<commitid>[^ ]+) (?P<description>.*)$`)
2020

@@ -33,7 +33,7 @@ func ActionLocalBookmarks() carapace.Action {
3333
// master@git (qvlkomxp 9a2e553b (empty) Merge pull request #939 from rsteube/docker-update-...)
3434
// master@origin (qvlkomxp 9a2e553b (empty) Merge pull request #939 from rsteube/docker-update-...)
3535
func ActionRemoteBookmarks(remote string) carapace.Action {
36-
return carapace.ActionExecCommand("jj", "bookmark", "list", "--all")(func(output []byte) carapace.Action {
36+
return actionExecJJ("bookmark", "list", "--all")(func(output []byte) carapace.Action {
3737
lines := strings.Split(string(output), "\n")
3838
rLocal := regexp.MustCompile(`^(?P<bookmark>[^@: ]+): (?P<changeid>[^ ]+) (?P<commitid>[^ ]+) (?P<description>.*)$`)
3939
rRemote := regexp.MustCompile(`^(?P<bookmark>[^@: ]+)@(?P<remote>[^: ]+): (?P<changeid>[^ ]+) (?P<commitid>[^ ]+) (?P<description>.*)$`)

pkg/actions/tools/jj/commit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// @ (HEAD)
1515
// @- (commit message)
1616
func ActionHeadCommits(limit int) carapace.Action {
17-
return carapace.ActionExecCommand("jj", "log", "--no-graph", "--template", `description.first_line() ++ "\n"`, "--revisions", "::@", "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
17+
return actionExecJJ("log", "--no-graph", "--template", `description.first_line() ++ "\n"`, "--revisions", "::@", "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
1818
lines := strings.Split(string(output), "\n")
1919

2020
vals := make([]string, 0)
@@ -30,7 +30,7 @@ func ActionHeadCommits(limit int) carapace.Action {
3030
// 04 (build(deps): bump github.com/creack/pty from 1.1.18 to 1.1.20 (#8265))
3131
// 03 (fix(release create): Handle latest flag value when updating the rel...)
3232
func ActionPrevCommits(limit int) carapace.Action {
33-
return carapace.ActionExecCommand("jj", "log", "--no-graph", "--template", `commit_id.short() ++ "\t" ++ description.first_line() ++ "\n"`, "--revisions", "::@", "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
33+
return actionExecJJ("log", "--no-graph", "--template", `commit_id.short() ++ "\t" ++ description.first_line() ++ "\n"`, "--revisions", "::@", "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
3434
lines := strings.Split(string(output), "\n")
3535
format := "%0" + strconv.Itoa(len(strconv.Itoa(limit-1))) + "d"
3636

@@ -44,7 +44,7 @@ func ActionPrevCommits(limit int) carapace.Action {
4444
}
4545

4646
func ActionNextCommits(limit int) carapace.Action {
47-
return carapace.ActionExecCommand("jj", "log", "--no-graph", "--template", `commit_id.short() ++ "\t" ++ description.first_line() ++ "\n"`, "--revisions", "@-::", "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
47+
return actionExecJJ("log", "--no-graph", "--template", `commit_id.short() ++ "\t" ++ description.first_line() ++ "\n"`, "--revisions", "@-::", "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
4848
lines := strings.Split(string(output), "\n")
4949
format := "%0" + strconv.Itoa(len(strconv.Itoa(limit-1))) + "d"
5050

@@ -62,7 +62,7 @@ func ActionNextCommits(limit int) carapace.Action {
6262
// 3b61f0a729f7 (compat: added cobra bridge)
6363
// 3c2e7535ce2f (elivsh: testing tag support)
6464
func ActionRecentCommits(limit int) carapace.Action {
65-
return carapace.ActionExecCommand("jj", "log", "--no-graph", "--template", `commit_id.short() ++ "\n" ++ description.first_line() ++ "\n"`, "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
65+
return actionExecJJ("log", "--no-graph", "--template", `commit_id.short() ++ "\n" ++ description.first_line() ++ "\n"`, "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
6666
lines := strings.Split(string(output), "\n")
6767
return carapace.ActionValuesDescribed(lines[:len(lines)-1]...).Style(styles.Git.Commit)
6868
}).Tag("recent commits")

pkg/actions/tools/jj/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func actionConfigs(includeDefaults bool) carapace.Action {
2525
if includeDefaults {
2626
args = append(args, "--include-defaults")
2727
}
28-
return carapace.ActionExecCommand("jj", args...)(func(output []byte) carapace.Action {
28+
return actionExecJJ(args...)(func(output []byte) carapace.Action {
2929
var config map[string]any
3030
if err := toml.Unmarshal(output, &config); err != nil {
3131
return carapace.ActionMessage(err.Error())

pkg/actions/tools/jj/conflict.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
// ActionConflicts completes conflicts
1010
func ActionConflicts(revision string) carapace.Action {
11-
return carapace.ActionExecCommand("jj", "resolve", "--list", "--revision", revision)(func(output []byte) carapace.Action {
11+
return actionExecJJ("resolve", "--list", "--revision", revision)(func(output []byte) carapace.Action {
1212
lines := strings.Split(string(output), "\n")
1313

1414
vals := make([]string, 0)

pkg/actions/tools/jj/diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func ActionRevDiffs(revisions ...string) carapace.Action {
3030
return carapace.ActionMessage("invalid amount of args [ActionRevChanges]")
3131
}
3232

33-
return carapace.ActionExecCommand("jj", "--color", "never", "diff", "--summary", "--from", from, "--to", to)(func(output []byte) carapace.Action {
33+
return actionExecJJ("diff", "--summary", "--from", from, "--to", to)(func(output []byte) carapace.Action {
3434
lines := strings.Split(string(output), "\n")
3535

3636
vals := make([]string, 0)
@@ -55,7 +55,7 @@ func ActionRevChanges(revisions ...string) carapace.Action {
5555
for _, revision := range revisions {
5656
args = append(args, "--revisions", revision)
5757
}
58-
return carapace.ActionExecCommand("jj", args...)(func(output []byte) carapace.Action {
58+
return actionExecJJ(args...)(func(output []byte) carapace.Action {
5959
lines := strings.Split(string(output), "\n")
6060

6161
vals := make([]string, 0)

pkg/actions/tools/jj/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func ActionRevFiles(rev string) carapace.Action {
1616
if rev == "" {
1717
rev = "@"
1818
}
19-
return carapace.ActionExecCommand("jj", "file", "list", "--revision", rev)(func(output []byte) carapace.Action {
19+
return actionExecJJ("file", "list", "--revision", rev)(func(output []byte) carapace.Action {
2020
lines := strings.Split(string(output), "\n")
2121
return carapace.ActionValues(lines[:len(lines)-1]...).MultiParts("/").StyleF(style.ForPathExt)
2222
})

pkg/actions/tools/jj/jj.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package jj
2+
3+
import "github.com/carapace-sh/carapace"
4+
5+
func actionExecJJ(arg ...string) func(f func(output []byte) carapace.Action) carapace.Action {
6+
return func(f func(output []byte) carapace.Action) carapace.Action {
7+
return carapace.ActionExecCommand("jj", append([]string{"--color", "never"}, arg...)...)(func(output []byte) carapace.Action {
8+
return f(output)
9+
})
10+
}
11+
}

pkg/actions/tools/jj/operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// c9f7e4956c01 (initialize repo)
1313
// 902f106af7d3 (check out git remote's default branch)
1414
func ActionOperations(limit int) carapace.Action {
15-
return carapace.ActionExecCommand("jj", "op", "log", "--no-graph", "--template", `id.short() ++ "\t" ++ description ++ "\n"`, "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
15+
return actionExecJJ("op", "log", "--no-graph", "--template", `id.short() ++ "\t" ++ description ++ "\n"`, "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
1616
lines := strings.Split(string(output), "\n")
1717

1818
vals := make([]string, 0)

pkg/actions/tools/jj/remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// carapace (https://github.com/carapace-sh/carapace)
1212
// carapace-bin (https://github.com/carapace-sh/carapace-bin)
1313
func ActionRemotes() carapace.Action {
14-
return carapace.ActionExecCommand("jj", "git", "remote", "list")(func(output []byte) carapace.Action {
14+
return actionExecJJ("git", "remote", "list")(func(output []byte) carapace.Action {
1515
lines := strings.Split(string(output), "\n")
1616
vals := make([]string, 0)
1717
for _, line := range lines[:len(lines)-1] {

pkg/actions/tools/jj/signing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
// ActionSigningKeys completes signing keys based on the user's configuration
1212
func ActionSigningKeys() carapace.Action {
13-
return carapace.ActionExecCommand("jj", "config", "get", "signing.backend")(func(output []byte) carapace.Action {
13+
return actionExecJJ("config", "get", "signing.backend")(func(output []byte) carapace.Action {
1414
backend := strings.TrimSpace(string(output))
1515

1616
if backend == "ssh" {

0 commit comments

Comments
 (0)