From e24647701854e6264b7fbe92ea58e6626f3dcdbd Mon Sep 17 00:00:00 2001 From: Oleg Pykhalov Date: Tue, 8 Jan 2019 22:39:54 +0300 Subject: add copy commit hash command --- gui/diffview.go | 15 +++++++++++++++ gui/keybindings.go | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/gui/diffview.go b/gui/diffview.go index 9f49456..4bd3590 100644 --- a/gui/diffview.go +++ b/gui/diffview.go @@ -5,6 +5,7 @@ import ( "github.com/isacikgoz/gitbatch/core/command" "github.com/jroimartin/gocui" + "github.com/atotto/clipboard" ) var diffReturnView string @@ -54,6 +55,20 @@ func (gui *Gui) openCommitDiffView(g *gocui.Gui, v *gocui.View) (err error) { return nil } +// copy hash of the selected commit +// called from commitview, so initial view is commitview +func (gui *Gui) copyCommitHash(g *gocui.Gui, v *gocui.View) (err error) { + r := gui.getSelectedRepository() + commit := r.State.Commit + clipboard.WriteAll(commit.Hash) + if err != nil { + if err != gocui.ErrUnknownView { + return err + } + } + return nil +} + // called from status, so initial view may be stagedview or unstaged view func (gui *Gui) openFileDiffView(g *gocui.Gui, v *gocui.View) (err error) { diff --git a/gui/keybindings.go b/gui/keybindings.go index 668fe90..19cb114 100644 --- a/gui/keybindings.go +++ b/gui/keybindings.go @@ -477,6 +477,15 @@ func (gui *Gui) generateKeybindings() error { Description: "Show commit diff", Vital: true, }, + { + View: commitViewFeature.Name, + Key: 'c', + Modifier: gocui.ModNone, + Handler: gui.copyCommitHash, + Display: "c", + Description: "Copy commit hash", + Vital: true, + }, // upstream confirmation { View: confirmationViewFeature.Name, -- cgit v1.2.3