You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.1 KiB

package main
import (
"os"
"os/exec"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
idents, err := gpgKeys()
if err != nil {
log.Err(err).Msg("could not get GPG keys")
}
var ident Identity
if idents != nil {
ident, err = gpgPrompt(idents)
if err != nil {
log.Fatal().Err(err).Msg("could not get GPG key")
}
}
if ident.Key == "" {
ident, err = userPrompt()
if err != nil {
log.Fatal().Err(err).Msg("could not prompt for user/email")
}
}
git("user.name", ident.Name)
git("user.email", ident.Email)
if ident.Key != "" {
git("commit.gpgsign", "true")
git("user.signingkey", ident.SigningKey())
}
log.Info().
Str("user.name", ident.Name).
Str("user.email", ident.Email).
Bool("commit.gpgsign", ident.Key != "").
Str("user.signingkey", ident.SigningKey()).
Msg("Git Identity Set!")
}
func git(key, value string) {
cmd := exec.Command("git", "config", "--local", key, value)
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatal().Err(err).Msg(string(out))
}
if string(out) != "" {
log.Info().Msg(string(out))
}
}