diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-05-01 14:14:29 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-05-01 14:14:29 +1000 |
commit | 4dd09ee0d58a508e80e676e0f00e96f6a37f3689 (patch) | |
tree | 8d21f0a04cc2999353a7f1152b8f6118e8dd45f5 /pkg/gui/controllers | |
parent | d85f4792af2a760fe07251e66e286e5a6929c26d (diff) |
allow copying commit author to clipboard
Diffstat (limited to 'pkg/gui/controllers')
-rw-r--r-- | pkg/gui/controllers/basic_commits_controller.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index a951349cc..66455eecf 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -1,6 +1,8 @@ package controllers import ( + "fmt" + "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -126,6 +128,13 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e }, Key: 'm', }, + { + DisplayString: self.c.Tr.LcCommitAuthor, + OnPress: func() error { + return self.copyAuthorToClipboard(commit) + }, + Key: 'a', + }, }, }) } @@ -170,6 +179,23 @@ func (self *BasicCommitsController) copyCommitDiffToClipboard(commit *models.Com return nil } +func (self *BasicCommitsController) copyAuthorToClipboard(commit *models.Commit) error { + author, err := self.git.Commit.GetCommitAuthor(commit.Sha) + if err != nil { + return self.c.Error(err) + } + + formattedAuthor := fmt.Sprintf("%s <%s>", author.Name, author.Email) + + self.c.LogAction(self.c.Tr.Actions.CopyCommitAuthorToClipboard) + if err := self.os.CopyToClipboard(formattedAuthor); err != nil { + return self.c.Error(err) + } + + self.c.Toast(self.c.Tr.CommitAuthorCopiedToClipboard) + return nil +} + func (self *BasicCommitsController) copyCommitMessageToClipboard(commit *models.Commit) error { message, err := self.git.Commit.GetCommitMessage(commit.Sha) if err != nil { |