Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Keybinds #154

Open
Makeshift opened this issue Oct 18, 2020 · 4 comments
Open

Custom Keybinds #154

Makeshift opened this issue Oct 18, 2020 · 4 comments

Comments

@Makeshift
Copy link

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
Copy link
Author

Found it:

resh/cmd/cli/main.go

Lines 129 to 163 in a4d2744

if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, layout.Next); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, layout.Next); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyCtrlN, gocui.ModNone, layout.Next); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, layout.Prev); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyCtrlP, gocui.ModNone, layout.Prev); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyArrowRight, gocui.ModNone, layout.SelectPaste); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyEnter, gocui.ModNone, layout.SelectExecute); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyCtrlG, gocui.ModNone, layout.AbortPaste); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyCtrlR, gocui.ModNone, layout.SwitchModes); err != nil {
log.Panicln(err)
}

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

@erwin
Copy link

erwin commented Jun 25, 2022

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
Copy link
Owner

curusarn commented Feb 4, 2024

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants