Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sync"
"time"

"github.com/atotto/clipboard"
"github.com/awesome-gocui/gocui"
"github.com/curusarn/resh/internal/cfg"
"github.com/curusarn/resh/internal/datadir"
Expand Down Expand Up @@ -160,6 +161,10 @@ func runReshCli(out *output.Output, config cfg.Config) (string, int) {
out.FatalE(errMsg, err)
}

if err := g.SetKeybinding("", gocui.KeyCtrlY, gocui.ModNone, layout.CopyCommand); err != nil {
out.FatalE(errMsg, err)
}

ctx := context.Background()
layout.updateData(ctx, *query)
layout.updateRawData(ctx, *query)
Expand Down Expand Up @@ -252,6 +257,27 @@ func (m manager) AbortPaste(g *gocui.Gui, v *gocui.View) error {
return nil
}

func (m manager) CopyCommand(g *gocui.Gui, v *gocui.View) error {
m.s.lock.Lock()
defer m.s.lock.Unlock()
if m.s.rawMode {
if m.s.highlightedItem < len(m.s.rawData) {
err := clipboard.WriteAll(m.s.rawData[m.s.highlightedItem].CmdLineOut)
if err != nil {
return err
}
}
} else {
if m.s.highlightedItem < len(m.s.data) {
err := clipboard.WriteAll(m.s.data[m.s.highlightedItem].CmdLineOut)
if err != nil {
return err
}
}
}
return nil
}

func (m manager) updateData(ctx context.Context, input string) {
timeStart := time.Now()
sugar := m.out.Logger.Sugar()
Expand Down Expand Up @@ -543,7 +569,7 @@ func (m manager) normalMode(g *gocui.Gui, v *gocui.View) error {
var statusLineHeight int = len(statusLine)

helpLineHeight := 1
const helpLine = "HELP: type to search, UP/DOWN or CTRL+P/N to select, RIGHT to edit, ENTER to execute, CTRL+G to abort, CTRL+C/D to quit; " +
const helpLine = "HELP: type to search, UP/DOWN or CTRL+P/N to select, RIGHT to edit, ENTER to execute, CTRL+G to abort, CTRL+C/D to quit; CTRL+Y to copy; " +
"FLAGS: G = this git repo, E# = exit status #"
// "TIP: when resh-cli is launched command line is used as initial search query"

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/tcell/v2 v2.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
Loading