Skip to content

Commit

Permalink
Merge pull request #2164 from rsteube/git-stash-dash
Browse files Browse the repository at this point in the history
git: stash - dash completion
  • Loading branch information
rsteube authored Jan 9, 2024
2 parents edc621b + 0a906bb commit 2757896
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ exec($(carapace _carapace))
# zsh (~/.zshrc)
source <(carapace _carapace)
```
XXX
5 changes: 5 additions & 0 deletions completers/git_completer/cmd/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/spf13/cobra"
)

Expand All @@ -15,4 +16,8 @@ var stashCmd = &cobra.Command{
func init() {
carapace.Gen(stashCmd).Standalone()
rootCmd.AddCommand(stashCmd)

carapace.Gen(stashCmd).DashAnyCompletion(
git.ActionChanges(git.ChangeOpts{Unstaged: true}).FilterArgs(),
)
}
14 changes: 14 additions & 0 deletions completers/git_completer/cmd/stash_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/spf13/cobra"
)

Expand All @@ -28,4 +29,17 @@ func init() {
carapace.Gen(stash_pushCmd).FlagCompletion(carapace.ActionMap{
"pathspec-from-file": carapace.ActionFiles(),
})

carapace.Gen(stash_pushCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if stash_pushCmd.Flag("pathspec-from-file").Changed {
return carapace.ActionValues()
}
return git.ActionChanges(git.ChangeOpts{Unstaged: true})
}),
)

carapace.Gen(stash_pushCmd).DashAnyCompletion(
carapace.ActionPositional(stash_pushCmd),
)
}

0 comments on commit 2757896

Please sign in to comment.