Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Aug 25, 2023
1 parent d303856 commit b2bbe29
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/rsteube/carapace-bin

go 1.19
go 1.21

require (
github.com/pelletier/go-toml v1.9.5
Expand Down
80 changes: 41 additions & 39 deletions pkg/actions/tools/git/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,48 @@ func (o RefOption) Default() RefOption {
// HEAD~1 (last commit msg)
// v0.0.1 (last commit msg)
func ActionRefs(refOption RefOption) carapace.Action {
return carapace.ActionCallback(func(cOrig carapace.Context) carapace.Action {
return carapace.ActionMultiParts("~", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
batch := carapace.Batch()

if refOption.LocalBranches {
batch = append(batch, ActionLocalBranches())
}

if refOption.RemoteBranches {
batch = append(batch, ActionRemoteBranches(""))
}

if refOption.Commits > 0 {
batch = append(batch, ActionRecentCommits(refOption.Commits))
}

if refOption.HeadCommits > 0 {
batch = append(batch, ActionHeadCommits(refOption.HeadCommits))
}

if refOption.Tags {
batch = append(batch, ActionTags())
}

if refOption.Stashes {
batch = append(batch, ActionStashes())
}

if refOption.Notes {
batch = append(batch, ActionNotes())
}

return batch.ToA()
default:
ref := cOrig.Value[:strings.LastIndex(cOrig.Value, "~")]
return ActionRefCommits(ref)
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if !strings.ContainsAny(c.Value, "~^") {
batch := carapace.Batch()

if refOption.LocalBranches {
batch = append(batch, ActionLocalBranches())
}

if refOption.RemoteBranches {
batch = append(batch, ActionRemoteBranches(""))
}

if refOption.Commits > 0 {
batch = append(batch, ActionRecentCommits(refOption.Commits))
}

if refOption.HeadCommits > 0 {
batch = append(batch, ActionHeadCommits(refOption.HeadCommits))
}

if refOption.Tags {
batch = append(batch, ActionTags())
}

if refOption.Stashes {
batch = append(batch, ActionStashes())
}

if refOption.Notes {
batch = append(batch, ActionNotes())
}
})

return batch.ToA()
}

index := max(strings.LastIndex(c.Value, "~"), strings.LastIndex(c.Value, "^"))
switch c.Value[index] {
case '^':
return ActionRefParents(c.Value[:index]).Prefix(c.Value[:index+1])
default: // '~'
return ActionRefCommits(c.Value[:index]).Prefix(c.Value[:index+1])
}
})
}

Expand Down

0 comments on commit b2bbe29

Please sign in to comment.