Update keyboard shortcuts script to show all runtime keybinds (#70)

* feat: Add a keyboard shortcuts helper

This commit:

* Changes keybinds to use `bindd` and adds descriptions for each one
* Changes the keybinds script to use `hyprctl binds` to inspect runtime keybinds
and generate a wofi menu to search/inspect keybinds

* Rely on 'order defined' for sorting

Using `hyprctl binds` lets us get the binds in the order they're
defined. This lets us be deliberate about what keybinds we want to show
up at the top of the presented window.

* Skip cache file for keybinds

* Strip extra newline causing double spacing
This commit is contained in:
Nathan Anderson
2025-07-13 20:17:48 -04:00
committed by GitHub
parent 41b5893d32
commit 6433511873
8 changed files with 148 additions and 131 deletions

View File

@ -1,59 +1,64 @@
#!/bin/bash #!/bin/bash
# A script to display Hyprland keybindings defined in your configuration # Define modifier flags as associative array for name lookup
# using wofi for an interactive search menu. # per https://github.com/hyprwm/Hyprland/blob/main/src/devices/IKeyboard.hpp#L13-L22
declare -A MODIFIER_NAMES=(
[$((1 << 0))]="SHIFT"
[$((1 << 1))]="CAPS"
[$((1 << 2))]="CTRL"
[$((1 << 3))]="ALT"
[$((1 << 4))]="MOD2"
[$((1 << 5))]="MOD3"
[$((1 << 6))]="SUPER"
[$((1 << 7))]="MOD5"
)
USER_HYPRLAND_CONF="$HOME/.config/hypr/hyprland.conf" decode_modmask() {
OMARCHY_BINDINGS_CONF="$HOME/.local/share/omarchy/default/hypr/bindings.conf $HOME/.local/share/omarchy/default/hypr/bindings/tiling.conf $HOME/.local/share/omarchy/default/hypr/bindings/utilities.conf $HOME/.local/share/omarchy/default/hypr/bindings.conf $HOME/.local/share/omarchy/default/hypr/media.conf" local modifiers=$1
local result=()
OMARCHY_BINDINGS_CONF="$HOME/.local/share/omarchy/default/hypr/bindings.conf \ for bit in "${!MODIFIER_NAMES[@]}"; do
$HOME/.local/share/omarchy/default/hypr/bindings/tiling.conf \ if (( modifiers & bit )); then
$HOME/.local/share/omarchy/default/hypr/bindings/utilities.conf \ result+=("${MODIFIER_NAMES[$bit]}")
$HOME/.local/share/omarchy/default/hypr/media.conf" fi
done
# Process the configuration file to extract and format keybindings # Output all detected modifiers (plus-separated)
# 1. `grep` finds all lines starting with 'bind' (allowing for leading spaces). echo "${result[*]}"
# 2. The first `sed` removes comments (anything after a '#'). }
# 3. `awk` does the heavy lifting of formatting the output.
# - It sets the field separator to a comma ','.
# - It removes the 'bind... =' part from the beginning of the line.
# - It joins the key combination (e.g., "SUPER + Q").
# - It joins the command that the key executes.
# - It prints everything in a nicely aligned format.
# 4. The final `sed` cleans up any leftover commas from the end of lines.
grep -h '^[[:space:]]*bind' $USER_HYPRLAND_CONF $OMARCHY_BINDINGS_CONF |
sed 's/#.*//' |
sed '/^[[:space:]]*$/d' |
sort -u |
awk -F, '
{
# Strip trailing comments
sub(/#.*/, "");
# Remove the "bind... =" part and surrounding whitespace # Read live keybinds, not config file
sub(/^[[:space:]]*bind[^=]*=(\+[[:space:]])?(exec, )?[[:space:]]*/, "", $1); OLD_IFS=$IFS
IFS=$'\n'
readarray -t KEYBINDS < <(hyprctl -j binds | jq -cr '.[]')
IFS=$OLD_IFS
# Combine the modifier and key (first two fields) # Loop over each keybind and pipe results to wofi for inspection/execution
key_combo = $1 " + " $2; # Format to send to wofi:
#
# <dispatcher> -- <arg> #<Modifier Keys> <Key> - <Description>
# exec -- alacritty #SUPER return - Launch a Terminal
# or
# exit -- #SUPER+ALT ESCAPE - Logout
#
# Wofi's pre-display-cmd looks for the '#' and prints everything after it
# in the wofi window. When we pipe that to `xargs hyprctl dispatch`, the
# Comment character ensures we ignore the description text and only executes
# the dispatcher + arg.
for keyconfig in "${KEYBINDS[@]}"; do
# Use pipe '|' to delimit results
IFS="|" read modmask key keycode description dispatcher arg < <(echo $(echo "$keyconfig" | jq -r '[.modmask, .key, .keycode, .description, .dispatcher, .arg] | join("|")'))
keys=($(decode_modmask $modmask) $key)
IFS=$OLD_IFS
# Clean up: strip leading "+" if present, trim spaces # We can't use IFS here, as it only supports single characters
gsub(/^[ \t]*\+?[ \t]*/, "", key_combo); delimiter=" + "
gsub(/[ \t]+$/, "", key_combo);
# Reconstruct the command from the remaining fields # Join the array elements with the delimiter
action = ""; combo=$(printf "%s$delimiter" "${keys[@]}")
for (i = 3; i <= NF; i++) {
action = action $i (i < NF ? "," : "");
}
# Clean up trailing commas, remove leading "exec, ", and trim # Remove the trailing delimiter
sub(/,$/, "", action); combo="${combo%$delimiter}"
gsub(/(^|,)[[:space:]]*exec[[:space:]]*,?/, "", action);
gsub(/^[ \t]+|[ \t]+$/, "", action);
gsub(/[ \t]+/, " ", key_combo); # Collapse multiple spaces to one
if (action != "") { printf "%s -- %s #%-30s → %s\n" "$dispatcher" "$arg" "$combo" "$description"
printf "%-35s → %s\n", key_combo, action; done | flock --nonblock /tmp/.wofi.lock -c "wofi --cache-file /dev/null --width 40% --height 70% -d -i -p 'Hyprland Keybindings' --style=\"$HOME/.local/share/omarchy/default/wofi/search.css\" -m --pre-display-cmd \"echo '%s' | cut -d'#' -f2 | tr -d '\n'\" | xargs hyprctl dispatch"
}
}' |
flock --nonblock /tmp/.wofi.lock -c "wofi -dmenu -i --width 60% --height 70% -p 'Hyprland Keybindings' -O alphabetical --style=\"$HOME/.local/share/omarchy/default/wofi/search.css\""

8
bin/omarchy-toggle-dnd Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
set -e
makoctl mode -t do-not-disturb > /dev/null
makoctl mode | grep -q 'do-not-disturb' \
&& notify-send "Silenced notifications" \
|| notify-send "Enabled notifications"

View File

@ -1,16 +1,8 @@
# Deprecated bindings file. New installations include everything directly. # Deprecated bindings file. New installations include everything directly.
# Order matters for how they show up when you press SUPER + K to see the
# defined keybinds
bind = SUPER, return, exec, $terminal source = ~/.local/share/omarchy/default/hypr/bindings/01-important.conf
bind = SUPER, F, exec, $fileManager
bind = SUPER, B, exec, $browser
bind = SUPER, M, exec, $music
bind = SUPER, N, exec, $terminal -e nvim
bind = SUPER, T, exec, $terminal -e btop
bind = SUPER, D, exec, $terminal -e lazydocker
bind = SUPER, G, exec, $messenger
bind = SUPER, O, exec, obsidian -disable-gpu
bind = SUPER, slash, exec, $passwordManager
source = ~/.local/share/omarchy/default/hypr/bindings/media.conf source = ~/.local/share/omarchy/default/hypr/bindings/media.conf
source = ~/.local/share/omarchy/default/hypr/bindings/tiling.conf source = ~/.local/share/omarchy/default/hypr/bindings/tiling.conf
source = ~/.local/share/omarchy/default/hypr/bindings/utilities.conf source = ~/.local/share/omarchy/default/hypr/bindings/utilities.conf

View File

@ -0,0 +1,14 @@
# Launching
bindd = SUPER, space, Application Launcher, exec, pkill wofi || wofi --show drun --sort-order=alphabetical --style="$HOME/.local/share/omarchy/default/wofi/search.css"
bindd = SUPER, K, Show Keybindings, exec, ~/.local/share/omarchy/bin/omarchy-show-keybindings
bindd = SUPER, return, Launch a Terminal, exec, $terminal
bindd = SUPER, F, Launch a File Manager, exec, $fileManager
bindd = SUPER, B, Launch a Browser, exec, $browser
bindd = SUPER, M, Launch a Music Player, exec, $music
bindd = SUPER, N, Launch nvim, exec, $terminal -e nvim
bindd = SUPER, T, Launch btop, exec, $terminal -e btop
bindd = SUPER, D, Launch lazydocker, exec, $terminal -e lazydocker
bindd = SUPER, G, Launch a Messenger App, exec, $messenger
bindd = SUPER, O, Launch Obsidian, exec, obsidian -disable-gpu
bindd = SUPER, slash, Launch a Password Manager, exec, $passwordManager

View File

@ -1,13 +1,13 @@
# Laptop multimedia keys for volume and LCD brightness # Laptop multimedia keys for volume, media control, and LCD brightness
bindel = ,XF86AudioRaiseVolume, exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+ bindeld = ,XF86AudioRaiseVolume, Raise Volume, exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+
bindel = ,XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- bindeld = ,XF86AudioLowerVolume, Lower Volume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
bindel = ,XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle bindeld = ,XF86AudioMute, Mute Speakers, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
bindel = ,XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle bindeld = ,XF86AudioMicMute, Mute Mic, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
bindel = ,XF86MonBrightnessUp, exec, brightnessctl -e4 -n2 set 5%+ bindeld = ,XF86MonBrightnessUp, Raise Brightness, exec, brightnessctl -e4 -n2 set 5%+
bindel = ,XF86MonBrightnessDown, exec, brightnessctl -e4 -n2 set 5%- bindeld = ,XF86MonBrightnessDown, Lower Brightness, exec, brightnessctl -e4 -n2 set 5%-
# Requires playerctl # Requires playerctl
bindl = , XF86AudioNext, exec, playerctl next bindld = , XF86AudioNext, Next Track, exec, playerctl next
bindl = , XF86AudioPause, exec, playerctl play-pause bindld = , XF86AudioPause, Pause Media, exec, playerctl play-pause
bindl = , XF86AudioPlay, exec, playerctl play-pause bindld = , XF86AudioPlay, Pause Media, exec, playerctl play-pause
bindl = , XF86AudioPrev, exec, playerctl previous bindld = , XF86AudioPrev, Previous Track, exec, playerctl previous

View File

@ -1,58 +1,58 @@
# Close window # Close window
bind = SUPER, W, killactive, bindd = SUPER, W, Close Window, killactive,
# Control tiling # Control tiling
bind = SUPER, J, togglesplit, # dwindle bindd = SUPER, J, Toggle Split, togglesplit, # dwindle
bind = SUPER, P, pseudo, # dwindle bindd = SUPER, P, Toggle Pseudo, pseudo # dwindle
bind = SUPER, V, togglefloating, bindd = SUPER, V, Toggle Floating, togglefloating,
bindd = SUPER CTRL, F, Toggle Fullscreen, fullscreen
# Move focus with mainMod + arrow keys # Move focus with mainMod + arrow keys
bind = SUPER, left, movefocus, l bindd = SUPER, left, Move Focus Left, movefocus, l
bind = SUPER, right, movefocus, r bindd = SUPER, right, Move Focus Right, movefocus, r
bind = SUPER, up, movefocus, u bindd = SUPER, up, Move Focus Up, movefocus, u
bind = SUPER, down, movefocus, d bindd = SUPER, down, Move Focus Down, movefocus, d
# Switch workspaces with mainMod + [0-9] # Switch workspaces with mainMod + [0-9]
bind = SUPER, code:10, workspace, 1 bindd = SUPER, code:10, Switch to workspace 1, workspace, 1
bind = SUPER, code:11, workspace, 2 bindd = SUPER, code:11, Switch to workspace 2, workspace, 2
bind = SUPER, code:12, workspace, 3 bindd = SUPER, code:12, Switch to workspace 3, workspace, 3
bind = SUPER, code:13, workspace, 4 bindd = SUPER, code:13, Switch to workspace 4, workspace, 4
bind = SUPER, code:14, workspace, 5 bindd = SUPER, code:14, Switch to workspace 5, workspace, 5
bind = SUPER, code:15, workspace, 6 bindd = SUPER, code:15, Switch to workspace 6, workspace, 6
bind = SUPER, code:16, workspace, 7 bindd = SUPER, code:16, Switch to workspace 7, workspace, 7
bind = SUPER, code:17, workspace, 8 bindd = SUPER, code:17, Switch to workspace 8, workspace, 8
bind = SUPER, code:18, workspace, 9 bindd = SUPER, code:18, Switch to workspace 9, workspace, 9
bind = SUPER, code:19, workspace, 10 bindd = SUPER, code:19, Switch to workspace 10, workspace, 10
# Move active window to a workspace with mainMod + SHIFT + [0-9] # Move active window to a workspace with mainMod + SHIFT + [0-9]
bind = SUPER SHIFT, code:10, movetoworkspace, 1 bindd = SUPER SHIFT, code:10, Move Active Window to workspace 1, movetoworkspace, 1
bind = SUPER SHIFT, code:11, movetoworkspace, 2 bindd = SUPER SHIFT, code:11, Move Active Window to workspace 2, movetoworkspace, 2
bind = SUPER SHIFT, code:12, movetoworkspace, 3 bindd = SUPER SHIFT, code:12, Move Active Window to workspace 3, movetoworkspace, 3
bind = SUPER SHIFT, code:13, movetoworkspace, 4 bindd = SUPER SHIFT, code:13, Move Active Window to workspace 4, movetoworkspace, 4
bind = SUPER SHIFT, code:14, movetoworkspace, 5 bindd = SUPER SHIFT, code:14, Move Active Window to workspace 5, movetoworkspace, 5
bind = SUPER SHIFT, code:15, movetoworkspace, 6 bindd = SUPER SHIFT, code:15, Move Active Window to workspace 6, movetoworkspace, 6
bind = SUPER SHIFT, code:16, movetoworkspace, 7 bindd = SUPER SHIFT, code:16, Move Active Window to workspace 7, movetoworkspace, 7
bind = SUPER SHIFT, code:17, movetoworkspace, 8 bindd = SUPER SHIFT, code:17, Move Active Window to workspace 8, movetoworkspace, 8
bind = SUPER SHIFT, code:18, movetoworkspace, 9 bindd = SUPER SHIFT, code:18, Move Active Window to workspace 9, movetoworkspace, 9
bind = SUPER SHIFT, code:19, movetoworkspace, 10 bindd = SUPER SHIFT, code:19, Move Active Window to workspace 10, movetoworkspace, 10
# Swap active window with the one next to it with mainMod + SHIFT + arrow keys # Swap active window with the one next to it with mainMod + SHIFT + arrow keys
bind = SUPER SHIFT, left, swapwindow, l bindd = SUPER SHIFT, left, Swap Active Window with Left, swapwindow, l
bind = SUPER SHIFT, right, swapwindow, r bindd = SUPER SHIFT, right, Swap Active Window with Right, swapwindow, r
bind = SUPER SHIFT, up, swapwindow, u bindd = SUPER SHIFT, up, Swap Active Window with Up, swapwindow, u
bind = SUPER SHIFT, down, swapwindow, d bindd = SUPER SHIFT, down, Swap Active Window with Down, swapwindow, d
# Resize active window # Resize active window
bind = SUPER, minus, resizeactive, -100 0 bindd = SUPER, minus, Shrink Window Horizontally, resizeactive, -100 0
bind = SUPER, equal, resizeactive, 100 0 bindd = SUPER, equal, Grow Window Horizontally, resizeactive, 100 0
bind = SUPER SHIFT, minus, resizeactive, 0 -100 bindd = SUPER SHIFT, minus, Shrink Window Vertically, resizeactive, 0 -100
bind = SUPER SHIFT, equal, resizeactive, 0 100 bindd = SUPER SHIFT, equal, Grow Window Vertically, resizeactive, 0 100
# Scroll through existing workspaces with mainMod + scroll # Scroll through existing workspaces with mainMod + scroll
bind = SUPER, mouse_down, workspace, e+1 bindd = SUPER, mouse_down, Scroll Down though workspaces, workspace, e+1
bind = SUPER, mouse_up, workspace, e-1 bindd = SUPER, mouse_up, Scroll Up through workspaces, workspace, e-1
# Move/resize windows with mainMod + LMB/RMB and dragging # Move/resize windows with mainMod + LMB/RMB and dragging
bindm = SUPER, mouse:272, movewindow bindmd = SUPER, mouse:272, Move Windows, movewindow
bindm = SUPER, mouse:273, resizewindow bindmd = SUPER, mouse:273, Resize Windows, resizewindow

View File

@ -1,32 +1,29 @@
# Launching
bind = SUPER, space, exec, pkill wofi || wofi --show drun --sort-order=alphabetical --style="$HOME/.local/share/omarchy/default/wofi/search.css"
bind = SUPER, K, exec, ~/.local/share/omarchy/bin/omarchy-show-keybindings
# Aesthetics # Aesthetics
bind = SUPER SHIFT, SPACE, exec, pkill -SIGUSR1 waybar bindd = SUPER SHIFT, SPACE, Hide Waybar, exec, pkill -SIGUSR1 waybar
bind = SUPER CTRL, SPACE, exec, ~/.local/share/omarchy/bin/swaybg-next bindd = SUPER ALT, SPACE, Reload Waybar, exec, pkill -SIGUSR2 waybar
bind = SUPER SHIFT CTRL, SPACE, exec, ~/.local/share/omarchy/bin/omarchy-theme-next bindd = SUPER CTRL, SPACE, Next Wallpaper, exec, ~/.local/share/omarchy/bin/swaybg-next
bindd = SUPER SHIFT CTRL, SPACE, Next Theme, exec, ~/.local/share/omarchy/bin/omarchy-theme-next
# Notifications # Notifications
bind = SUPER, comma, exec, makoctl dismiss bindd = SUPER, comma, Dismiss Notification, exec, makoctl dismiss
bind = SUPER SHIFT, comma, exec, makoctl dismiss --all bindd = SUPER SHIFT, comma, Dismiss All Notifications, exec, makoctl dismiss --all
bind = SUPER CTRL, comma, exec, makoctl mode -t do-not-disturb && makoctl mode | grep -q 'do-not-disturb' && notify-send "Silenced notifications" || notify-send "Enabled notifications" bindd = SUPER CTRL, comma, Toggle Do Not Disturb, exec, ~/.local/share/omarchy/bin/omarchy-toggle-dnd
# Power menu controls lock, suspend, relaunch, restart, shutdown # Power menu controls lock, suspend, relaunch, restart, shutdown
bind = SUPER, ESCAPE, exec, ~/.local/share/omarchy/bin/omarchy-power-menu bindd = SUPER, ESCAPE, Show Power Menu (Lock/Suspend/Relaunch/Restart/Shutdown), exec, ~/.local/share/omarchy/bin/omarchy-power-menu
# Toggle idling # Toggle idling
bind = SUPER CTRL, I, exec, ~/.local/share/omarchy/bin/omarchy-toggle-idle bindd = SUPER CTRL, I, Toggle Idling, exec, ~/.local/share/omarchy/bin/omarchy-toggle-idle
# Control Apple Display brightness # Control Apple Display brightness
bind = CTRL, F1, exec, ~/.local/share/omarchy/bin/apple-display-brightness -5000 bindd = CTRL, F1, Dim Apple Screen Brightness, exec, ~/.local/share/omarchy/bin/apple-display-brightness -5000
bind = CTRL, F2, exec, ~/.local/share/omarchy/bin/apple-display-brightness +5000 bindd = CTRL, F2, Raise Apple Screen Brightness, exec, ~/.local/share/omarchy/bin/apple-display-brightness +5000
bind = SHIFT CTRL, F2, exec, ~/.local/share/omarchy/bin/apple-display-brightness +60000 bindd = SHIFT CTRL, F2, Set Apple Screen Brightness to Max, exec, ~/.local/share/omarchy/bin/apple-display-brightness +60000
# Screenshots # Screenshots
bind = , PRINT, exec, hyprshot -m region bindd = , PRINT, Screenshot a Region, exec, hyprshot -m region
bind = SHIFT, PRINT, exec, hyprshot -m window bindd = SHIFT, PRINT, Screenshot a Window, exec, hyprshot -m window
bind = CTRL, PRINT, exec, hyprshot -m output bindd = CTRL, PRINT, Screenshot Desktop, exec, hyprshot -m output
# Color picker # Color picker
bind = SUPER, PRINT, exec, hyprpicker -a bindd = SUPER, PRINT, Pick a Color, exec, hyprpicker -a

View File

@ -3,4 +3,5 @@ yay -S --noconfirm --needed \
imagemagick \ imagemagick \
mariadb-libs postgresql-libs \ mariadb-libs postgresql-libs \
github-cli \ github-cli \
lazygit lazydocker-bin lazygit lazydocker-bin \
jq