curusarn / resh

RESH ❯❯ Contextual shell history for zsh and bash
MIT License
1.01k stars 19 forks source link

Custom Keybinds #154

Open Makeshift opened 3 years ago

Makeshift commented 3 years ago

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 commented 3 years ago

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)" <git@connor-bell.com>
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
erwin commented 2 years ago

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
curusarn commented 7 months ago

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

Makeshift commented 7 months ago

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