1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

Add copy commit attributes option

This commit is contained in:
Luka Markušić 2022-03-24 21:04:33 +01:00 committed by Jesse Duffield
parent bbaa651943
commit 540edb0bf4
8 changed files with 155 additions and 53 deletions

View File

@ -155,7 +155,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>g</kbd>: reset to this commit
<kbd>space</kbd>: checkout commit
<kbd>T</kbd>: tag commit
<kbd>ctrl+y</kbd>: copy commit message to clipboard
<kbd>y</kbd>: copy commit attribute
<kbd>o</kbd>: open commit in browser
<kbd>enter</kbd>: view selected item's files
</pre>

View File

@ -195,7 +195,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>g</kbd>: reset naar deze commit
<kbd>space</kbd>: checkout commit
<kbd>T</kbd>: tag commit
<kbd>ctrl+y</kbd>: kopieer commit bericht naar klembord
<kbd>y</kbd>: copy commit attribute
<kbd>o</kbd>: open commit in browser
<kbd>enter</kbd>: bekijk gecommite bestanden
</pre>

View File

@ -68,7 +68,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>g</kbd>: zresetuj do tego commita
<kbd>space</kbd>: checkout commit
<kbd>T</kbd>: tag commit
<kbd>ctrl+y</kbd>: copy commit message to clipboard
<kbd>y</kbd>: copy commit attribute
<kbd>o</kbd>: open commit in browser
<kbd>enter</kbd>: przeglądaj pliki commita
</pre>

View File

@ -207,8 +207,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>g</kbd>: 重置为此提交
<kbd>space</kbd>: 检出提交
<kbd>T</kbd>: 标签提交
<kbd>ctrl+y</kbd>: 将提交消息复制到剪贴板
<kbd>o</kbd>: 在浏览器中打开提交
<kbd>y</kbd>: copy commit attribute
<kbd>o</kbd>: open commit in browser
<kbd>enter</kbd>: 查看提交的文件
</pre>

View File

@ -74,6 +74,12 @@ func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) {
return strings.TrimSpace(message), err
}
func (self *CommitCommands) GetCommitDiff(commitSha string) (string, error) {
cmdStr := "git show --no-color " + commitSha
diff, err := self.cmd.New(cmdStr).DontLog().RunWithOutput()
return diff, err
}
func (self *CommitCommands) GetCommitMessageFirstLine(sha string) (string, error) {
return self.GetCommitMessagesFirstLine([]string{sha})
}

View File

@ -229,28 +229,28 @@ type KeybindingBranchesConfig struct {
}
type KeybindingCommitsConfig struct {
SquashDown string `yaml:"squashDown"`
RenameCommit string `yaml:"renameCommit"`
RenameCommitWithEditor string `yaml:"renameCommitWithEditor"`
ViewResetOptions string `yaml:"viewResetOptions"`
MarkCommitAsFixup string `yaml:"markCommitAsFixup"`
CreateFixupCommit string `yaml:"createFixupCommit"`
SquashAboveCommits string `yaml:"squashAboveCommits"`
MoveDownCommit string `yaml:"moveDownCommit"`
MoveUpCommit string `yaml:"moveUpCommit"`
AmendToCommit string `yaml:"amendToCommit"`
PickCommit string `yaml:"pickCommit"`
RevertCommit string `yaml:"revertCommit"`
CherryPickCopy string `yaml:"cherryPickCopy"`
CherryPickCopyRange string `yaml:"cherryPickCopyRange"`
PasteCommits string `yaml:"pasteCommits"`
TagCommit string `yaml:"tagCommit"`
CheckoutCommit string `yaml:"checkoutCommit"`
ResetCherryPick string `yaml:"resetCherryPick"`
CopyCommitMessageToClipboard string `yaml:"copyCommitMessageToClipboard"`
OpenLogMenu string `yaml:"openLogMenu"`
OpenInBrowser string `yaml:"openInBrowser"`
ViewBisectOptions string `yaml:"viewBisectOptions"`
SquashDown string `yaml:"squashDown"`
RenameCommit string `yaml:"renameCommit"`
RenameCommitWithEditor string `yaml:"renameCommitWithEditor"`
ViewResetOptions string `yaml:"viewResetOptions"`
MarkCommitAsFixup string `yaml:"markCommitAsFixup"`
CreateFixupCommit string `yaml:"createFixupCommit"`
SquashAboveCommits string `yaml:"squashAboveCommits"`
MoveDownCommit string `yaml:"moveDownCommit"`
MoveUpCommit string `yaml:"moveUpCommit"`
AmendToCommit string `yaml:"amendToCommit"`
PickCommit string `yaml:"pickCommit"`
RevertCommit string `yaml:"revertCommit"`
CherryPickCopy string `yaml:"cherryPickCopy"`
CherryPickCopyRange string `yaml:"cherryPickCopyRange"`
PasteCommits string `yaml:"pasteCommits"`
TagCommit string `yaml:"tagCommit"`
CheckoutCommit string `yaml:"checkoutCommit"`
ResetCherryPick string `yaml:"resetCherryPick"`
CopyCommitAttributeToClipboard string `yaml:"copyCommitAttributeToClipboard"`
OpenLogMenu string `yaml:"openLogMenu"`
OpenInBrowser string `yaml:"openInBrowser"`
ViewBisectOptions string `yaml:"viewBisectOptions"`
}
type KeybindingStashConfig struct {
@ -496,28 +496,28 @@ func GetDefaultConfig() *UserConfig {
FetchRemote: "f",
},
Commits: KeybindingCommitsConfig{
SquashDown: "s",
RenameCommit: "r",
RenameCommitWithEditor: "R",
ViewResetOptions: "g",
MarkCommitAsFixup: "f",
CreateFixupCommit: "F",
SquashAboveCommits: "S",
MoveDownCommit: "<c-j>",
MoveUpCommit: "<c-k>",
AmendToCommit: "A",
PickCommit: "p",
RevertCommit: "t",
CherryPickCopy: "c",
CherryPickCopyRange: "C",
PasteCommits: "v",
TagCommit: "T",
CheckoutCommit: "<space>",
ResetCherryPick: "<c-R>",
CopyCommitMessageToClipboard: "<c-y>",
OpenLogMenu: "<c-l>",
OpenInBrowser: "o",
ViewBisectOptions: "b",
SquashDown: "s",
RenameCommit: "r",
RenameCommitWithEditor: "R",
ViewResetOptions: "g",
MarkCommitAsFixup: "f",
CreateFixupCommit: "F",
SquashAboveCommits: "S",
MoveDownCommit: "<c-j>",
MoveUpCommit: "<c-k>",
AmendToCommit: "A",
PickCommit: "p",
RevertCommit: "t",
CherryPickCopy: "c",
CherryPickCopyRange: "C",
PasteCommits: "v",
TagCommit: "T",
CheckoutCommit: "<space>",
ResetCherryPick: "<c-R>",
CopyCommitAttributeToClipboard: "y",
OpenLogMenu: "<c-l>",
OpenInBrowser: "o",
ViewBisectOptions: "b",
},
Stash: KeybindingStashConfig{
PopStash: "g",

View File

@ -165,9 +165,10 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
Description: self.c.Tr.LcTagCommit,
},
{
Key: opts.GetKey(opts.Config.Commits.CopyCommitMessageToClipboard),
Handler: self.checkSelected(self.copyCommitMessageToClipboard),
Description: self.c.Tr.LcCopyCommitMessageToClipboard,
Key: opts.GetKey(opts.Config.Commits.CopyCommitAttributeToClipboard),
Handler: self.checkSelected(self.copyCommitAttribute),
Description: self.c.Tr.LcCopyCommitAttributeToClipboard,
OpensMenu: true,
},
{
Key: opts.GetKey(opts.Config.Commits.OpenInBrowser),
@ -599,6 +600,78 @@ func (self *LocalCommitsController) gotoBottom() error {
return nil
}
func (self *LocalCommitsController) copyCommitAttribute(commit *models.Commit) error {
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard,
Items: []*types.MenuItem{
{
DisplayString: self.c.Tr.LcCommitSha,
OnPress: func() error {
return self.copyCommitSHAToClipboard(commit)
},
},
{
DisplayString: self.c.Tr.LcCommitURL,
OnPress: func() error {
return self.copyCommitURLToClipboard(commit)
},
},
{
DisplayString: self.c.Tr.LcCommitDiff,
OnPress: func() error {
return self.copyCommitDiffToClipboard(commit)
},
},
{
DisplayString: self.c.Tr.LcCommitMessage,
OnPress: func() error {
return self.copyCommitMessageToClipboard(commit)
},
},
},
})
}
func (self *LocalCommitsController) copyCommitSHAToClipboard(commit *models.Commit) error {
self.c.LogAction(self.c.Tr.Actions.CopyCommitSHAToClipboard)
if err := self.os.CopyToClipboard(commit.Sha); err != nil {
return self.c.Error(err)
}
self.c.Toast(self.c.Tr.CommitSHACopiedToClipboard)
return nil
}
func (self *LocalCommitsController) copyCommitURLToClipboard(commit *models.Commit) error {
url, err := self.helpers.Host.GetCommitURL(commit.Sha)
if err != nil {
return err
}
self.c.LogAction(self.c.Tr.Actions.CopyCommitURLToClipboard)
if err := self.os.CopyToClipboard(url); err != nil {
return self.c.Error(err)
}
self.c.Toast(self.c.Tr.CommitURLCopiedToClipboard)
return nil
}
func (self *LocalCommitsController) copyCommitDiffToClipboard(commit *models.Commit) error {
diff, err := self.git.Commit.GetCommitDiff(commit.Sha)
if err != nil {
return self.c.Error(err)
}
self.c.LogAction(self.c.Tr.Actions.CopyCommitDiffToClipboard)
if err := self.os.CopyToClipboard(diff); err != nil {
return self.c.Error(err)
}
self.c.Toast(self.c.Tr.CommitDiffCopiedToClipboard)
return nil
}
func (self *LocalCommitsController) copyCommitMessageToClipboard(commit *models.Commit) error {
message, err := self.git.Commit.GetCommitMessage(commit.Sha)
if err != nil {
@ -611,7 +684,6 @@ func (self *LocalCommitsController) copyCommitMessageToClipboard(commit *models.
}
self.c.Toast(self.c.Tr.CommitMessageCopiedToClipboard)
return nil
}

View File

@ -362,8 +362,13 @@ type TranslationSet struct {
LcOpenDiffingMenu string
LcOpenExtrasMenu string
LcShowingGitDiff string
LcCommitDiff string
LcCopyCommitShaToClipboard string
LcCommitSha string
LcCommitURL string
LcCopyCommitMessageToClipboard string
LcCommitMessage string
LcCopyCommitAttributeToClipboard string
LcCopyBranchNameToClipboard string
LcCopyFileNameToClipboard string
LcCopyCommitFileNameToClipboard string
@ -415,6 +420,9 @@ type TranslationSet struct {
ExtrasTitle string
PushingTagStatus string
PullRequestURLCopiedToClipboard string
CommitDiffCopiedToClipboard string
CommitSHACopiedToClipboard string
CommitURLCopiedToClipboard string
CommitMessageCopiedToClipboard string
LcCopiedToClipboard string
ErrCannotEditDirectory string
@ -505,6 +513,10 @@ type Actions struct {
MoveCommitUp string
MoveCommitDown string
CopyCommitMessageToClipboard string
CopyCommitDiffToClipboard string
CopyCommitSHAToClipboard string
CopyCommitURLToClipboard string
CopyCommitAttributeToClipboard string
CustomCommand string
DiscardAllChangesInDirectory string
DiscardUnstagedChangesInDirectory string
@ -941,8 +953,13 @@ func EnglishTranslationSet() TranslationSet {
// the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part
LcOpenExtrasMenu: "open command log menu",
LcShowingGitDiff: "showing output for:",
LcCommitDiff: "commit diff",
LcCopyCommitShaToClipboard: "copy commit SHA to clipboard",
LcCommitSha: "commit SHA",
LcCommitURL: "commit URL",
LcCopyCommitMessageToClipboard: "copy commit message to clipboard",
LcCommitMessage: "commit message",
LcCopyCommitAttributeToClipboard: "copy commit attribute",
LcCopyBranchNameToClipboard: "copy branch name to clipboard",
LcCopyFileNameToClipboard: "copy the file name to the clipboard",
LcCopyCommitFileNameToClipboard: "copy the committed file name to the clipboard",
@ -993,6 +1010,9 @@ func EnglishTranslationSet() TranslationSet {
ExtrasTitle: "Extras",
PushingTagStatus: "pushing tag",
PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard",
CommitDiffCopiedToClipboard: "Commit diff copied to clipboard",
CommitSHACopiedToClipboard: "Commit SHA copied to clipboard",
CommitURLCopiedToClipboard: "Commit URL copied to clipboard",
CommitMessageCopiedToClipboard: "Commit message copied to clipboard",
LcCopiedToClipboard: "copied to clipboard",
ErrCannotEditDirectory: "Cannot edit directory: you can only edit individual files",
@ -1064,6 +1084,10 @@ func EnglishTranslationSet() TranslationSet {
CreateLightweightTag: "Create lightweight tag",
CreateAnnotatedTag: "Create annotated tag",
CopyCommitMessageToClipboard: "Copy commit message to clipboard",
CopyCommitDiffToClipboard: "Copy commit diff to clipboard",
CopyCommitSHAToClipboard: "Copy commit SHA to clipboard",
CopyCommitURLToClipboard: "Copy commit URL to clipboard",
CopyCommitAttributeToClipboard: "Copy to clipboard",
MoveCommitUp: "Move commit up",
MoveCommitDown: "Move commit down",
CustomCommand: "Custom command",