resh icon indicating copy to clipboard operation
resh copied to clipboard

Custom Keybinds

Open Makeshift opened this issue 3 years ago • 4 comments

Is it possible to have custom keybinds, or rebind the current keybinds?

For example, I would like to rebind Enter to paste onto the commandline for editing (instead of Right), and Esc to abort and paste the current query.

If this isn't an intended feature, would you be able to direct me to the file where in-app keybinds are located? I'm not incredibly familiar with Go.

Thanks!

Makeshift avatar Oct 18 '20 10:10 Makeshift

Found it: https://github.com/curusarn/resh/blob/a4d2744f08b192842226863a097f4bb676fcf007/cmd/cli/main.go#L129-L163

Stupid simple patch just for my needs:

From 373da55192b43c0a36fb95dcd74e97cf1d8a5837 Mon Sep 17 00:00:00 2001
From: "Connor Bell (Makeshift)" <[email protected]>
Date: Sun, 18 Oct 2020 11:33:33 +0100
Subject: [PATCH] Makeshift custom keybinds

---
 cmd/cli/main.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/cmd/cli/main.go b/cmd/cli/main.go
index 1578643..b9358e5 100644
--- a/cmd/cli/main.go
+++ b/cmd/cli/main.go
@@ -142,13 +142,13 @@ func runReshCli() (string, int) {
                log.Panicln(err)
        }

-       if err := g.SetKeybinding("", gocui.KeyArrowRight, gocui.ModNone, layout.SelectPaste); err != nil {
+       if err := g.SetKeybinding("", gocui.KeyArrowRight, gocui.ModNone, layout.SelectExecute); err != nil {
                log.Panicln(err)
        }
-       if err := g.SetKeybinding("", gocui.KeyEnter, gocui.ModNone, layout.SelectExecute); err != nil {
+       if err := g.SetKeybinding("", gocui.KeyEnter, gocui.ModNone, layout.SelectPaste); err != nil {
                log.Panicln(err)
        }
-       if err := g.SetKeybinding("", gocui.KeyCtrlG, gocui.ModNone, layout.AbortPaste); err != nil {
+       if err := g.SetKeybinding("", gocui.KeyEsc, gocui.ModNone, layout.AbortPaste); err != nil {
                log.Panicln(err)
        }
        if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
--
2.25.1

Makeshift avatar Oct 18 '20 10:10 Makeshift

Thank you very much @Makeshift for posting that! I was wanting to do exactly the same.

Esc for Exit Enter for Paste not for Exec

Fits much better with my workflow now.

Also, for anyone else wanting to do this, note that you can go build . for many go projects, but the author has actually built a nice Makefile that grabs all of the required source dependencies.

So once you've edited the keybindings you need, just a simple:

make
make install
# which runs scripts/install.sh

or if you don't need to test, just

make install

erwin avatar Jun 25 '22 23:06 erwin

Thank you both! 🙌

I do plan to refresh the UI using a much better terminal UI library - https://charm.sh And as part of that I want to introduce changed bindings where Enter works as Edit

curusarn avatar Feb 04 '24 14:02 curusarn

Wow, that's a beautiful library, thanks for the link! Definitely going to investigate that for my own projects too

Makeshift avatar Feb 04 '24 16:02 Makeshift