jj_completer: updated to jujutsu 0.27.0

- Added `--include-remotes` flag to `jj bookmark forget`
  - Added `jj sign/unsign` commands
This commit is contained in:
aftix 2025-03-14 15:31:27 -05:00
parent 913db045cf
commit b243b54b03
5 changed files with 116 additions and 0 deletions

View File

@ -17,6 +17,7 @@ func init() {
carapace.Gen(bookmark_forgetCmd).Standalone()
bookmark_forgetCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')")
bookmark_forgetCmd.Flags().Bool("include-remotes", false, "When forgetting a local bookmark, also forget any corresponding remote bookmarks")
bookmarkCmd.AddCommand(bookmark_forgetCmd)
carapace.Gen(bookmark_forgetCmd).PositionalAnyCompletion(

View File

@ -0,0 +1,27 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/jj"
"github.com/spf13/cobra"
)
var signCmd = &cobra.Command{
Use: "sign [OPTIONS]",
Short: "Cryptographically sign a revision",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(signCmd).Standalone()
signCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')")
signCmd.Flags().String("key", "", "The key used for signing")
signCmd.Flags().StringSliceP("revisions", "r", []string{"@"}, "What revision(s) to sign")
rootCmd.AddCommand(signCmd)
carapace.Gen(signCmd).FlagCompletion(carapace.ActionMap{
"key": jj.ActionSigningKeys(),
"revisions": jj.ActionRevSets(jj.RevOption{}.Default()),
})
}

View File

@ -0,0 +1,25 @@
package cmd
import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/jj"
"github.com/spf13/cobra"
)
var unsignCmd = &cobra.Command{
Use: "unsign [OPTIONS]",
Short: "Drop a cryptographic signature",
Run: func(cmd *cobra.Command, args []string) {},
}
func init() {
carapace.Gen(unsignCmd).Standalone()
unsignCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')")
unsignCmd.Flags().StringSliceP("revisions", "r", []string{"@"}, "What revision(s) to unsign")
rootCmd.AddCommand(unsignCmd)
carapace.Gen(unsignCmd).FlagCompletion(carapace.ActionMap{
"revisions": jj.ActionRevSets(jj.RevOption{}.Default()),
})
}

View File

@ -95,3 +95,41 @@ func ActionPrivateKeys() carapace.Action {
return carapace.ActionValuesDescribed(vals...).StyleF(style.ForPath)
})
}
// ActionSigningKeys completes the contents of public keys for which a private key exists
func ActionSigningKeys() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
abs, err := c.Abs("~/.ssh/")
if err != nil {
return carapace.ActionMessage(err.Error())
}
entries, err := os.ReadDir(abs)
if err != nil {
return carapace.ActionMessage(err.Error())
}
vals := make([]string, 0)
for _, entry := range entries {
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".pub") {
continue
}
path := abs + entry.Name()
privatePath := strings.TrimSuffix(path, ".pub")
if _, err := os.Stat(privatePath); err != nil {
continue
}
if contents, err := os.ReadFile(path); err == nil {
pubKeyLine := strings.Split(string(contents), "\n")[0]
pubKeyFields := strings.Fields(pubKeyLine)
if len(pubKeyFields) > 1 {
vals = append(vals, pubKeyFields[0]+" "+pubKeyFields[1], privatePath)
}
}
}
return carapace.ActionValuesDescribed(vals...)
})
}

View File

@ -0,0 +1,25 @@
package jj
import (
"strings"
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/net/ssh"
"github.com/carapace-sh/carapace-bin/pkg/actions/os"
)
// ActionSigningKeys completes signing keys based on the user's configuration
func ActionSigningKeys() carapace.Action {
return carapace.ActionExecCommand("jj", "config", "get", "signing.backend")(func(output []byte) carapace.Action {
backend := strings.TrimSpace(string(output))
if backend == "ssh" {
return ssh.ActionSigningKeys()
} else if backend == "gpg" {
return os.ActionGpgKeyIds()
}
// TODO: complete gpg signing keys
return carapace.ActionValues()
})
}