koekeishiya / skhd

Simple hotkey daemon for macOS
MIT License
6.24k stars 209 forks source link

vim-like modal keybindings workflow #152

Open nikhgupta opened 3 years ago

nikhgupta commented 3 years ago

Hello,

I wanted to share my skhd keybindings that I use with (SIP disabled) yabai to manage windows, launch apps, etc. I am using skhd as a central place for triggering shortcuts.

https://github.com/nikhgupta/dotfiles/blob/osx/user/.config/skhd/skhdrc#L74-L128 ^^ can be useful for VIM users. I can trigger my vim bindings using SPACE as leader and OSX bindings using CAPS LOCK as leader key.

However, I have one simple issue - when space does not have any windows, I can not display borders to know which modal state I am in.

If anyone has any ideas for displaying modal state or better yet, display cheat sheet for possible keybindings, please advise.

MuhammedZakir commented 3 years ago

If you stay in a mode only for a short time, then a simple notification using AppleScript is probably enough? If you want to know your current mode anytime, a simple(?) method would be to write your current mode to a file [1] each time you enter/exit one. Then, you can assign a key for calling a notification with that file's content, i.e. the current mode.

[1] This can be avoided if skhd supports setting/getting a variable.

nikhgupta commented 3 years ago

If you stay in a mode only for a short time, then a simple notification using AppleScript is probably enough? If you want to know your current mode anytime, a simple(?) method would be to write your current mode to a file [1] each time you enter/exit one. Then, you can assign a key for calling a notification with that file's content, i.e. the current mode.

[1] This can be avoided if skhd supports setting/getting a variable.

Would not that be a very obtrusive approach to any workflow?

I am looking for something like this (ideally): ref

MuhammedZakir commented 3 years ago

Would not that be a very obtrusive approach to any workflow?

  • It's not instant (keypresses are often very fast)

  • We can't display a lot of key bindings (aka cheat-sheet)

  • Has side-effects: these alerts would remain in Notification Center.

I am looking for something like this (ideally): ref

![](https://github.com/casouri/lunarySpoon/raw/master/screenshot/screenshot0.png) ![](https://github.com/casouri/lunarySpoon/raw/master/screenshot/screenshot1.png)

I thought you only want to know the name of current mode you are in. That's why I suggested notification. Many do the same thing with Karabiner-Elements too!* But, if you want to show next possible commands, then this indeed will be very difficult and ugly using alerts.

* You don't need to write to a file, however, as KE has conditionals.

Edit: About Hammerspoon: How slow was it? If it's really slow, do open an issue in Hammerspoon repo.

dsanson commented 3 years ago

I use spacebar https://github.com/cmacrae/spacebar, and have these lines in my skhdrc, which change the background color of spacebar when I change modes:

:: default : spacebar -m config background_color 0xff202020
:: m1 @ : spacebar -m config background_color  0xee009900
:: m2 @ : spacebar -m config background_color  0xee990000

There isn't any lag.

nikhgupta commented 3 years ago

@dsanson I was staying away from spacebar - it has some bugs. But, I liked your idea and started using it and implemented the same workflow. However, I still need to display cheat-sheet when I enter a particular mode - would be very handy. Preferably, I would want it to set an overlay over the whole screen and display available commands starting with that mode/chords. That would be a perfect setup :)

dsanson commented 3 years ago

Not quite what you want, but this is a decent gui fuzzy finder for OSX:

https://github.com/chipsenkbeil/choose

Not too hard to feed it a list of all your shortcuts with descriptions. That gives you a kind of cheatsheet, and it can be easily invoked from skhd. (While you are at it, might as well write a script that parses your selected command, and uses skhd -k to execute it for you.)

nikhgupta commented 3 years ago

@dsanson - ty. This is perfect - and exactly the last piece (rofi) in my switch from Arch to OSX. This is my ArchLinux setup and the rofi integration used to look like this.

glingy commented 1 year ago

I'll add that I just made a GUI like what was mentioned here since I wanted it too: https://github.com/glingy/skhdgui. It displays a window in the upper right corner when you are in a mode which lists possible shortcuts from that mode.

es183923 commented 1 year ago

You can also take a look at sketchybar. specifically this post: https://github.com/FelixKratz/SketchyBar/discussions/12 Also, you can take advantage ov sketchybar's popups feature to show the possible shortcuts. also, http://github.com/es183923/query-skhd is a POC of a way to easily parse the skhd config