Yabai: Adding helper for Karabiner-Elements bindings

Created on 27 Sep 2019  路  8Comments  路  Source: koekeishiya/yabai

Just a suggestion, but I'd like to share my helper script to configure Karabiner-Elements and run yabai commands with it.

background

I'm using Karabiner-Elements instead of skhd. This is because, on my computer, somehow it's really slow to execute shell commands via skhd.

Karabiner-Elements requires users to write (weird) JSON files for key mappings. If I share my script, it may be easier for some people to get their JSON files ready.

tests

It surely makes working JSON. But I've not tested the the example JSON in my PR (because I don't use it, excuse me).

else

Feel free not to merge my PR. Thanks.

Most helpful comment

This is a common issue with fish users, and the underlying culprit is always their non-interactive shell startup time.

# ~/.config/fish/config.fish
if status --is-interactive
    # heavy stuff goes here
end

skhd runs commands through $SHELL -c so people can use their environment variables.

All 8 comments

You might be experiencing slowness in skhd because of your shell. For example I have fish as my default shell and skhd will use that to run the commands and be very slow because of the shell startup time. You can brew edit skhd and add the following under Environment in the daemon plist declaration

<key>SHELL</key>
<string>/bin/dash</string>

Then you can brew reinstall skhd to apply the changes.

I also use Karabiner Elements for advanced complex modifications, but for yabai and simple shell commands, I really like how easy skhd is to configure. I think you might like this too if you can fix the slowness.

Sent with GitHawk

This is a common issue with fish users, and the underlying culprit is always their non-interactive shell startup time.

# ~/.config/fish/config.fish
if status --is-interactive
    # heavy stuff goes here
end

skhd runs commands through $SHELL -c so people can use their environment variables.

Thank you very much. Yes, I love the syntax of skhd, too, and it's better than Karabiner-Elements to invoke shell commands.

To let skhd use bash, somehow this did not work for me:

$ brew edit skhd # opens .rb file
$ brew services stop skhd
$ brew reinstall skhd
$ brew services start skhd

Edit: as @alin23 says below, I had to edit two plist definitions in the .rb file

So I directly edited this file (following a solution in the (issue):

$ nvim /usr/local/Cellar/skhd/0.3.4/homebrew.mxcl.skhd.plist

And.. I'm using skhd 馃榿 Thanks again.

So I could do this in ~/.config/fish/config.fish?

Edit: never mind. We can't return outside of function in fish.

if not status --is-interactive
    return
end
# heavy stuff goes here

I'll give it a try if skhd is updated.

The problem with editing the file directly is that the file will revert at the next skhd update or at the next daemon reload. You should try to get the brew edit solution working to avoid this. Pay attention to the .rb file because there are two plist definitions, you should add SHELL to both for good measure.

You could also try @dominiklohmann solution, I can't use it because I'm also using fish as a non-interactive command and I need the config always ready.

It makes sence. I appreciate your detailed answer.

@toyboot4e I'm not a fish user myself, but for zsh there are multiple files you can split your configuration into, e.g., .zshenv, .zprofile, and .zshrc. Just ask yourself whether you really need that fancy prompt in non-interactive mode鈥攚here it doesn't display anyways.

From a quick Google search, there seems to be a fish --profile ... command line interface for profiling your fish configuration.

Additionally, if you don't want to optimize your fish configuration, there's also launchctl setenv SHELL '/bin/sh', which sets the environment variable $SHELL to /bin/sh for all application bundles and processes launched via launchd. Note that this command needs to be run on every login, e.g. in a launch agent.

If you use skhd and yabai together, you could also just add SHELL='/bin/sh' skhd & to your ~/.config/yabai/yabairc file, although this is not a very robust solution.

@dominiklohmann Genius. I may take the last solution. Much appreciated!

Edit: @alin23's answer worked fine:
brew edit and then change shell (two) -> brew reinstall skhd -> brew services restart skhd

I didn't have /bin/dash so I used /bin/sh instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hum4n01d picture Hum4n01d  路  4Comments

koekeishiya picture koekeishiya  路  4Comments

haze picture haze  路  4Comments

mattsawyer77 picture mattsawyer77  路  4Comments

koekeishiya picture koekeishiya  路  4Comments