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

Adding helper for Karabiner-Elements bindings #267

Closed
toyboot4e opened this issue Sep 27, 2019 · 8 comments
Closed

Adding helper for Karabiner-Elements bindings #267

toyboot4e opened this issue Sep 27, 2019 · 8 comments

Comments

@toyboot4e
Copy link

toyboot4e commented Sep 27, 2019

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.

@alin23
Copy link

alin23 commented Sep 28, 2019

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

@dominiklohmann
Copy link
Collaborator

dominiklohmann commented Sep 28, 2019

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.

@toyboot4e
Copy link
Author

toyboot4e commented Sep 28, 2019

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.

@toyboot4e
Copy link
Author

toyboot4e commented Sep 28, 2019

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.

@alin23
Copy link

alin23 commented Sep 28, 2019

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.

@toyboot4e
Copy link
Author

It makes sence. I appreciate your detailed answer.

@dominiklohmann
Copy link
Collaborator

@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—where 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.

@toyboot4e
Copy link
Author

toyboot4e commented Sep 28, 2019

@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.

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