mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
Copy Tags to clipboard
Add an option to copy tag(s) to the clipboard. Works on both the Tags and Commits sections.
This commit is contained in:
parent
3722824298
commit
333802fffc
3 changed files with 88 additions and 43 deletions
|
@ -3,6 +3,7 @@ package controllers
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
|
@ -122,51 +123,67 @@ func (self *BasicCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
|
|||
}
|
||||
|
||||
func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) error {
|
||||
return self.c.Menu(types.CreateMenuOptions{
|
||||
Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard,
|
||||
Items: []*types.MenuItem{
|
||||
{
|
||||
Label: self.c.Tr.CommitHash,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitHashToClipboard(commit)
|
||||
},
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitSubject,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitSubjectToClipboard(commit)
|
||||
},
|
||||
Key: 's',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitMessage,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitMessageToClipboard(commit)
|
||||
},
|
||||
Key: 'm',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitURL,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitURLToClipboard(commit)
|
||||
},
|
||||
Key: 'u',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitDiff,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitDiffToClipboard(commit)
|
||||
},
|
||||
Key: 'd',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitAuthor,
|
||||
OnPress: func() error {
|
||||
return self.copyAuthorToClipboard(commit)
|
||||
},
|
||||
Key: 'a',
|
||||
items := []*types.MenuItem{
|
||||
{
|
||||
Label: self.c.Tr.CommitHash,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitHashToClipboard(commit)
|
||||
},
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitSubject,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitSubjectToClipboard(commit)
|
||||
},
|
||||
Key: 's',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitMessage,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitMessageToClipboard(commit)
|
||||
},
|
||||
Key: 'm',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitURL,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitURLToClipboard(commit)
|
||||
},
|
||||
Key: 'u',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitDiff,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitDiffToClipboard(commit)
|
||||
},
|
||||
Key: 'd',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CommitAuthor,
|
||||
OnPress: func() error {
|
||||
return self.copyAuthorToClipboard(commit)
|
||||
},
|
||||
Key: 'a',
|
||||
},
|
||||
}
|
||||
|
||||
commitTagsItem := types.MenuItem{
|
||||
Label: self.c.Tr.CommitTags,
|
||||
OnPress: func() error {
|
||||
return self.copyCommitTagsToClipboard(commit)
|
||||
},
|
||||
Key: 't',
|
||||
}
|
||||
|
||||
if len(commit.Tags) == 0 {
|
||||
commitTagsItem.DisabledReason = &types.DisabledReason{Text: self.c.Tr.NoTags}
|
||||
}
|
||||
|
||||
items = append(items, &commitTagsItem)
|
||||
|
||||
return self.c.Menu(types.CreateMenuOptions{
|
||||
Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard,
|
||||
Items: items,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -257,6 +274,18 @@ func (self *BasicCommitsController) copyCommitSubjectToClipboard(commit *models.
|
|||
return nil
|
||||
}
|
||||
|
||||
func (self *BasicCommitsController) copyCommitTagsToClipboard(commit *models.Commit) error {
|
||||
message := strings.Join(commit.Tags, "\n")
|
||||
|
||||
self.c.LogAction(self.c.Tr.Actions.CopyCommitTagsToClipboard)
|
||||
if err := self.c.OS().CopyToClipboard(message); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
self.c.Toast(self.c.Tr.CommitTagsCopiedToClipboard)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *BasicCommitsController) openInBrowser(commit *models.Commit) error {
|
||||
url, err := self.c.Helpers().Host.GetCommitURL(commit.Hash)
|
||||
if err != nil {
|
||||
|
|
|
@ -145,6 +145,13 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
|||
GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason,
|
||||
Description: self.c.Tr.CopyBranchNameToClipboard,
|
||||
},
|
||||
{
|
||||
ViewName: "tags",
|
||||
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
|
||||
Handler: self.handleCopySelectedSideContextItemCommitHashToClipboard,
|
||||
GetDisabledReason: self.getCopySelectedSideContextItemToClipboardDisabledReason,
|
||||
Description: self.c.Tr.CopyTagToClipboard,
|
||||
},
|
||||
{
|
||||
ViewName: "commits",
|
||||
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
|
||||
|
|
|
@ -612,9 +612,11 @@ type TranslationSet struct {
|
|||
CommitMessage string
|
||||
CommitSubject string
|
||||
CommitAuthor string
|
||||
CommitTags string
|
||||
CopyCommitAttributeToClipboard string
|
||||
CopyCommitAttributeToClipboardTooltip string
|
||||
CopyBranchNameToClipboard string
|
||||
CopyTagToClipboard string
|
||||
CopyPathToClipboard string
|
||||
CommitPrefixPatternError string
|
||||
CopySelectedTextToClipboard string
|
||||
|
@ -674,6 +676,8 @@ type TranslationSet struct {
|
|||
CommitMessageCopiedToClipboard string
|
||||
CommitSubjectCopiedToClipboard string
|
||||
CommitAuthorCopiedToClipboard string
|
||||
CommitTagsCopiedToClipboard string
|
||||
NoTags string
|
||||
PatchCopiedToClipboard string
|
||||
CopiedToClipboard string
|
||||
ErrCannotEditDirectory string
|
||||
|
@ -905,6 +909,7 @@ type Actions struct {
|
|||
CopyCommitURLToClipboard string
|
||||
CopyCommitAuthorToClipboard string
|
||||
CopyCommitAttributeToClipboard string
|
||||
CopyCommitTagsToClipboard string
|
||||
CopyPatchToClipboard string
|
||||
CustomCommand string
|
||||
DiscardAllChangesInDirectory string
|
||||
|
@ -1627,9 +1632,11 @@ func EnglishTranslationSet() *TranslationSet {
|
|||
CommitMessage: "Commit message",
|
||||
CommitSubject: "Commit subject",
|
||||
CommitAuthor: "Commit author",
|
||||
CommitTags: "Commit tags",
|
||||
CopyCommitAttributeToClipboard: "Copy commit attribute to clipboard",
|
||||
CopyCommitAttributeToClipboardTooltip: "Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author).",
|
||||
CopyBranchNameToClipboard: "Copy branch name to clipboard",
|
||||
CopyTagToClipboard: "Copy tag to clipboard",
|
||||
CopyPathToClipboard: "Copy path to clipboard",
|
||||
CopySelectedTextToClipboard: "Copy selected text to clipboard",
|
||||
CommitPrefixPatternError: "Error in commitPrefix pattern",
|
||||
|
@ -1688,6 +1695,8 @@ func EnglishTranslationSet() *TranslationSet {
|
|||
CommitMessageCopiedToClipboard: "Commit message copied to clipboard",
|
||||
CommitSubjectCopiedToClipboard: "Commit subject copied to clipboard",
|
||||
CommitAuthorCopiedToClipboard: "Commit author copied to clipboard",
|
||||
CommitTagsCopiedToClipboard: "Commit tags copied to clipboard",
|
||||
NoTags: "No tags",
|
||||
PatchCopiedToClipboard: "Patch copied to clipboard",
|
||||
CopiedToClipboard: "copied to clipboard",
|
||||
ErrCannotEditDirectory: "Cannot edit directories: you can only edit individual files",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue