Skip to content

Commit

Permalink
git: ActionRefs - fix delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Apr 16, 2024
1 parent df400e3 commit cabe748
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions completers/git_completer/cmd/show.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd

import (
"path/filepath"
"strings"

"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/git"
"github.com/carapace-sh/carapace/pkg/util"
"github.com/carapace-sh/carapace/pkg/traverse"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -41,19 +41,21 @@ func init() {
})

carapace.Gen(showCmd).PositionalAnyCompletion(
carapace.ActionMultiParts(":", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return git.ActionRefs(git.RefOption{}.Default()).NoSpace()
case 1:
path, err := util.FindReverse(c.Dir, ".git")
if err != nil {
return carapace.ActionMessage(err.Error())
}
return git.ActionRefFiles(c.Parts[0]).Chdir(filepath.Dir(path))
default:
return carapace.ActionFiles()
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
delimiter := ":"
if strings.Contains(c.Value, "{") {
delimiter = "}:"
}

return carapace.ActionMultiPartsN(delimiter, 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return git.ActionRefs(git.RefOption{}.Default()).NoSpace()
default:
ref := c.Parts[0] + strings.TrimSuffix(delimiter, ":")
return git.ActionRefFiles(ref).ChdirF(traverse.GitWorkTree)
}
})
}),
)
}

0 comments on commit cabe748

Please sign in to comment.