Interact with this post using Mastodon or
sxhkd: why another keybinders?
Published on
The concept of keybinders should not be a secret for you. If you’re using a tiling windows manager, you are even probably already familiar with assigning keyboard shortcuts to actions within its configuration file. That’s what I used to do for years using awesomewm, i3, or dwm. Once I moved to bspwm, I’ve also be introduced to sxhkd and I first missed the point of yet another keybinders. Let’s see why sxhkd stands out among the various keybinders available for Linux.
In simple words, sxhkd’s secret is the format of its configuration file which supports a simple notation for mapping multiple shortcuts to multiple commands in parallel. This allows for a streamlined configuration file where you “group” similar keybindings instead of duplicated them.
Here are some examples of what that means:
# Assign 3 keybindings to 3 commands in just 2 lines:
# alt + g > launch gvim
# alt + f > launch firefox
# alt + t > launch thunderbird
mod1 + {g,f,t}
{gvim,firefox,thunderbird}
# Assign 3 keybindings to 3 commands (changing the argument of a command) in just 2 lines:
# super + alt + XF86Eject > run sudo systemctl suspend
# super + ctrl + XF86Eject > run sudo systemctl reboot
# super + alt + ctrl + XF86Eject > run sudo systemctl poweroff
super + {alt,ctrl,alt + ctrl} + XF86Eject
sudo systemctl {suspend,reboot,poweroff}
This is what you may be used too. Just in a more compressed format. Ready for more craziness?
# Assign 18 keybindings to 18 commands in just 2 lines again:
# control + [1-9] > switch to desktop [1-9] in bspwm
# control + shift + [1-9] > move window to desktop [1-9] in bspwm
control+{_,shift+}{1-9}
bspc {desktop -f,node -d} '^{1-9}' --follow
BTW, this also applies to remapping your mouse buttons like so:
button12
xdotool key control+Tab
Very useful when you have programmable buttons like on this little guy.
By now, I know that it’s hard to please my avid readers. Good news, sxhkd can also bind a command to a single press of a key. This is done by binding to a chord chain composed of the key press and key release event of a single key, as in the following:
# Press the super key to launch rofi in drun mode
Super_L; @Super_L
rofi -show drun
So I’ll leave it here and hope you’ll give this tiny, though extremely powerful, tool a try.
Thanks for your read. Hope it's been useful to you.
✄ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈
More food for thoughts? Check other posts about: #System