Using skhd and yabai as a launcher
Intro
One of the things I miss the most from my brief two month usage of GNU/Linux was the hackable, performant and joyfully simple selection of launchers available (e.g. dmenu, rofi, wofi, etc).
I’m yet to find anything that operates the same on mac. There is dmenu-mac but for this particular use case, I couldn’t get it to play nice.
So I looked to try hack together a solution from tools I already used. This lead me to using skhd and yabai as a ‘launcher’ of sorts. In this case, we’ll be setting up a keybind to bring up a terminal with gopass already running. You can substitute any other program with gopass. If you can run it from the terminal, you can run it via skhd.
For example, I have keybindst to brung up lf, english dictionary and my web browser.
Configs
skhd
The keybind comes first. skhd needs to launch a terminal instance and execute
gopass
. As I’m using wezterm (the best
terminal emulator under the sun), the entry in ~/.config/skhd/skhdrc
looks
like:
alt + cmd - g : /Applications/WezTerm.app/Contents/MacOS/wezterm start zsh -l -c gopass
Now we can hold down alt
- cmd
and press g
to spawn a terminal instance
with gopass running.
The full application is needed as otherwise skhd will launch a new instance of the terminal emulator, rather than using the already running process.
Some extra detail on the command:
cli start
is specific to wezterm.zsh -l
starts the spawned terminal process as a login shell, which loads our environment variables (important for gopass as it needs to know gpg directories as well as the $PASSWORD_STORE_DIR).-c <command>
takes the first argument as a command to execute (zsh docs).
yabai
yabai is built by the same developer and brings tiling window management to MacOS (the other major contender being Amethyst. With yabai we can also define rules for window management, which is how we’ll manage to get a new terminal instance running gopass to appear as a floating window in the center of the screen without altering the layout of our currently tiled windows.
Currently, the spawned terminal will be tiled as per the default rules of yabai. But it’s nicer to have it pop up in the center of the screen (i.e. like a launcher would). To do this we define a rule.
In ~/.config/yabai/yabairc
:
yabai -m rule --add app="^WezTerm$" title="^gopass$" manage=off grid=3:3:1:1:1:1
This informs yabai that when it encounters a window from WezTerm with the window title “gopass”, that it should not manage it (meaning don’t apply tiling rules) - however, we then apply our own tiling rules. The combination of these two ideas (don’t auto tile, but apply our own tiling) effectively means we can place a floating window where we please.
It is therefore important you take note of how your terminal emulator titles your windows. Typically, the default is to name it either as the current working directory, or the running process.
The grid
sytax is as follows:
grid=<rows>:<cols>:<start-x>:<start-y>:<width>:<height>
Broken down further:
<rows>:<cols>
is how many divisions make up your custom grid. e.g.3:3
gives you space for 9 windows.<start-x>:<start-y>
is which tile on the x axis and which on the y should the window be placed.<width>:<height>
defines how many tiles the window should span in x and y.
Now when we execute the keybind, we get a floating window in the center which runs gopass.