-
Notifications
You must be signed in to change notification settings - Fork 8
Add key alias support (closes #12) #21
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
Draft
jackielii
wants to merge
2
commits into
main
Choose a base branch
from
claude/plan-key-alias-support-01Q8Q1qANjKGsL4x1iy4JpfJ
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,167 @@ name = desired name for this mode | |
| command = command is executed through '$SHELL -c' | ||
| ``` | ||
|
|
||
|
|
||
| ## Key Aliases | ||
|
|
||
| Key aliases allow you to define reusable names for modifiers, keys, and key combinations, making configurations more readable and maintainable. | ||
|
|
||
| ### Syntax | ||
|
|
||
| ``` | ||
| alias_def = '.alias' <alias_name> <alias_value> | ||
|
|
||
| alias_name = '$' <identifier> | ||
|
|
||
| alias_value = <modifier_combo> | # Modifier alias | ||
| <key_spec> | # Key alias | ||
| <modifier_combo> '-' <key_spec> # Keysym alias | ||
|
|
||
| modifier_combo = <modifier> | <modifier> '+' <modifier_combo> | <alias_name> | ||
|
|
||
| key_spec = <literal> | <keycode> | <alias_name> | ||
| ``` | ||
|
|
||
| ### Alias Types | ||
|
|
||
| #### 1. Modifier Alias | ||
| Defines a modifier combination that can be reused and combined with other modifiers. | ||
|
|
||
| ```bash | ||
| .alias $super cmd + alt | ||
| .alias $hyper cmd + alt + ctrl + shift | ||
|
|
||
| # Use standalone | ||
| $super - h : echo "Super+H" | ||
|
|
||
| # Combine with other modifiers (like built-in hyper/meh) | ||
| $super + shift - h : echo "Super+Shift+H" | ||
| ``` | ||
|
|
||
| #### 2. Key Alias | ||
| Defines a key (with optional modifiers baked in) that can be used in key position. | ||
|
|
||
| ```bash | ||
| .alias $grave 0x32 # Hex keycode | ||
| .alias $exclaim shift - 1 # Key with modifier | ||
|
|
||
| # Use in key position | ||
| ctrl - $grave : echo "Ctrl+Grave" | ||
| ctrl - $exclaim : echo "Ctrl+Shift+1" # Modifiers merge! | ||
| ``` | ||
|
|
||
| #### 3. Keysym Alias | ||
| Defines a complete key combination (modifier + key) that can be used standalone or with additional modifiers. | ||
|
|
||
| ```bash | ||
| .alias $nav_left cmd - h | ||
| .alias $terminal_key cmd + shift - t | ||
|
|
||
| # Use standalone (macro expansion) | ||
| $nav_left : yabai -m window --focus west | ||
|
|
||
| # Add more modifiers | ||
| ctrl + $nav_left : yabai -m window --focus west # Becomes: ctrl+cmd - h | ||
| ``` | ||
|
|
||
| ### Nesting | ||
|
|
||
| Aliases can reference other aliases, and they are fully expanded at parse time: | ||
|
|
||
| ```bash | ||
| # Nested modifiers | ||
| .alias $super cmd + alt | ||
| .alias $mega $super + shift + ctrl # Expands to: cmd+alt+shift+ctrl | ||
|
|
||
| # Nested keys | ||
| .alias $grave 0x32 | ||
| .alias $tilde shift - $grave # Expands to: shift - 0x32 | ||
|
|
||
| # Nested keysyms | ||
| .alias $nav_left $super - h # Expands to: cmd+alt - h | ||
| .alias $special_nav ctrl + $nav_left # Expands to: ctrl+cmd+alt - h | ||
| ``` | ||
|
|
||
| ### Valid Usage Contexts | ||
|
|
||
| | Alias Type | Standalone | As Modifier | In Key Position | With + Modifier | | ||
| |------------|------------|-------------|-----------------|-----------------| | ||
| | Modifier | ✗ | ✓ | ✗ | ✓ | | ||
| | Key | ✗ | ✗ | ✓ | ✗ | | ||
| | Keysym | ✓ | ✗ | ✗ | ✓ | | ||
|
|
||
| ### Examples | ||
|
|
||
| ```bash | ||
| # Define aliases | ||
| .alias $super cmd + alt | ||
| .alias $mega $super + shift + ctrl | ||
| .alias $grave 0x32 | ||
| .alias $tilde shift - $grave | ||
| .alias $nav_left $super - h | ||
|
|
||
| # Modifier alias - can combine like hyper/meh | ||
| $super - t : open -a Terminal.app | ||
| $super + shift - t : open -a "New Terminal" | ||
|
|
||
| # Key alias - only in key position | ||
| ctrl - $grave : open -a Notes.app | ||
| $super - $tilde : open -a "System Settings" | ||
|
|
||
| # Keysym alias - standalone or with additional modifiers | ||
| $nav_left : yabai -m window --focus west | ||
| ctrl + $nav_left : yabai -m window --focus west # Add ctrl | ||
| ``` | ||
|
|
||
| ### Common Errors | ||
|
|
||
| #### Using Wrong Alias Type | ||
|
|
||
| ```bash | ||
| # ✗ WRONG: Key alias as modifier | ||
| .alias $grave 0x32 | ||
| $grave - t : echo "bad" # Error: $grave is a key, not a modifier | ||
|
|
||
| # ✓ CORRECT: Use in key position | ||
| ctrl - $grave : echo "good" | ||
|
|
||
| # ✗ WRONG: Modifier alias in key position | ||
| .alias $hyper cmd + alt | ||
| ctrl - $hyper : echo "bad" # Error: $hyper is a modifier, not a key | ||
|
|
||
| # ✓ CORRECT: Use as modifier | ||
| $hyper - t : echo "good" | ||
|
|
||
| # ✗ WRONG: Modifier alias standalone | ||
| .alias $hyper cmd + alt | ||
| $hyper : echo "bad" # Error: needs a key | ||
|
|
||
| # ✓ CORRECT: Add a key | ||
| $hyper - t : echo "good" | ||
| ``` | ||
|
|
||
| #### Missing $ Prefix | ||
|
|
||
| ```bash | ||
| .alias $hyper cmd + alt | ||
| hyper - t : echo "bad" # Error! Did you mean '$hyper'? | ||
| ``` | ||
|
|
||
| #### Circular References | ||
|
|
||
| ```bash | ||
| .alias $a $b + shift # Error: $b not defined yet | ||
| .alias $b $a + ctrl | ||
| ``` | ||
|
Comment on lines
+252
to
+257
|
||
|
|
||
| ### Benefits | ||
|
|
||
| - **Readability**: Complex modifier combinations get meaningful names | ||
| - **Maintainability**: Change definition once, affects all uses | ||
| - **Keyboard Layouts**: Abstract away layout-specific hex codes | ||
| - **Consistency**: Same modifier combo everywhere | ||
| - **Composability**: Combine aliases like built-in hyper/meh | ||
|
|
||
| ## Modifiers | ||
|
|
||
| ### Basic Modifiers | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two examples (lines 400-401) demonstrate the same keybinding calling the same command, which doesn't effectively showcase the feature. Line 400 shows
$focus_west(which expands to$super - h=cmd + alt - h) and line 401 showsctrl + $focus_west(which adds ctrl to makectrl + cmd + alt - h). However, both execute the identical command@yabai_focus("west"), making it unclear why you'd bind different key combinations to the same action. Consider either:@yabai_focus("west")vs@yabai_focus_and_warp("west"))