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

Any interest in sxhkd-like syntax for multiple similar bindings? #68

Open
Amar1729 opened this issue Mar 9, 2019 · 4 comments
Open

Comments

@Amar1729
Copy link

Amar1729 commented Mar 9, 2019

On linux I use sxhkd, where you can write keybinds like this:

# focus the node in the given direction
super + {h,j,k,l}
	bspc node -f {west,south,north,east}

Multiple {} groups are supported too, as long as the keybind and the command have the same number of groups.

In skhd of course the binding would be 8 lines long:

cmd + h
    chunkc tiling::window -f west
cmd + j
    chunkc tiling::window -f south
# same with k and l

I don't know if you're interested in functionality like this? (or if you don't care much about writing it, but would be fine with a PR?)

@koekeishiya
Copy link
Owner

The idea is interesting, but how would it interact with commands that include { as a part of the command, or commands that are chained through &&, || or ;

@Amar1729
Copy link
Author

Amar1729 commented Mar 11, 2019

Good point. For chained commands, I think it's fairly simple:

mod + {k1,k2} : cmd1 {arg1,arg2}; cmd2

parses to:

mod + k1: cmd1 arg1; cmd2
mod + k2: cmd1 arg2; cmd2

If the ; had been inside the braces:

mod + {k1,k2} : cmd1 {arg1;,arg2} cmd2

parses to:

mod + k1 : cmd1 arg1; cmd2
mod + k2 : cmd1 arg2 cmd2   # might silently fail or do something odd? so it's on the user to write a proper command

Would be similar with &&, || i think

For commands that include {}, I'm not sure of the best way to handle it.

  • disallow {} in the command if the keybind has them (would force user to write each individual keybind/command, which is the case now but might seem inconsistent)
  • Allow {} with something similar to the following rules I came up with:
  1. groups must not be inside quotes
  2. groups are only expanded if they contain the correct number of commas (based on the keybind definition)
# avoids incorrectly expanding the wrong group '{tmpfile}' since it doesn't contain commas
mod + {k1,k2} : 
    {touch,rm} ${tmpfile}

# avoids incorrectly expanding the {94..894} group since it is inside quotes
# correctly expands {iTerm2...Firefox} since it is non-quoted
mod + {q,w,e,r} : 
        osascript -e 'tell app "'{iTerm2,Kitty,qutebrowser,Firefox}'" to set bounds of front window to {94, 84, 699, 894}'

Are there other edge cases I'm missing where a command could include {}? Most cases I can think of with variables could just be contained in double quotes, while other cases I've seen with commands containing {} could be rewritten without them.

@koekeishiya
Copy link
Owner

I suppose that seems reasonable. Not sure when I would feel like working on something like this, so I suppose a PR would be the most appropriate if you would like this functionality in the near future.

@kcrwfrd
Copy link

kcrwfrd commented Jul 6, 2020

Would this allow users to cleanup something like

ctrl - 1 : yabai -m space --focus 1
ctrl - 2 : yabai -m space --focus 2
ctrl - 3 : yabai -m space --focus 3
ctrl - 4 : yabai -m space --focus 4
ctrl - 5 : yabai -m space --focus 5
ctrl - 6 : yabai -m space --focus 6

to

ctrl - { 1, 2, 3, 4, 5, 6 } : yabai -m space --focus { 1, 2, 3, 4, 5, 6 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants