From 9a99e24d6707e652be391a596a45a38cce709df8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 3 Jul 2025 13:14:42 -0700 Subject: [PATCH] Tweak keybindings and include the ones in the defaults too --- bin/omarchy-show-keybindings | 51 ++++++++++++++++++++++++++++++++ bin/show-keybindings | 56 ------------------------------------ default/hypr/bindings.conf | 3 +- 3 files changed, 53 insertions(+), 57 deletions(-) create mode 100755 bin/omarchy-show-keybindings delete mode 100755 bin/show-keybindings diff --git a/bin/omarchy-show-keybindings b/bin/omarchy-show-keybindings new file mode 100755 index 0000000..c517eaf --- /dev/null +++ b/bin/omarchy-show-keybindings @@ -0,0 +1,51 @@ +#!/bin/bash + +# A script to display Hyprland keybindings defined in your configuration +# using wofi for an interactive search menu. + +USER_HYPRLAND_CONF="$HOME/.config/hypr/hyprland.conf" +OMARCHY_BINDINGS_CONF="$HOME/.local/share/omarchy/default/hypr/bindings.conf" + +# Process the configuration file to extract and format keybindings +# 1. `grep` finds all lines starting with 'bind' (allowing for leading spaces). +# 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' "$HYPRLAND_CONF" "$OMARCHY_BINDINGS_CONF" | + awk -F, ' +{ + # Strip trailing comments + sub(/#.*/, ""); + + # Remove the "bind... =" part and surrounding whitespace + sub(/^[[:space:]]*bind[^=]*=(\+[[:space:]])?(exec, )?[[:space:]]*/, "", $1); + + # Combine the modifier and key (first two fields) + key_combo = $1 " + " $2; + + # Clean up: strip leading "+" if present, trim spaces + gsub(/^[ \t]*\+?[ \t]*/, "", key_combo); + gsub(/[ \t]+$/, "", key_combo); + + # Reconstruct the command from the remaining fields + action = ""; + for (i = 3; i <= NF; i++) { + action = action $i (i < NF ? "," : ""); + } + + # Clean up trailing commas, remove leading "exec, ", and trim + sub(/,$/, "", action); + gsub(/(^|,)[[:space:]]*exec[[:space:]]*,?/, "", action); + gsub(/^[ \t]+|[ \t]+$/, "", action); + gsub(/[ \t]+/, " ", key_combo); # Collapse multiple spaces to one + + if (action != "") { + printf "%-35s → %s\n", key_combo, action; + } +}' | + flock --nonblock /tmp/.wofi.lock -c "wofi -dmenu -i --width 60% --height 70% -p 'Hyprland Keybindings' -O alphabetical" diff --git a/bin/show-keybindings b/bin/show-keybindings deleted file mode 100755 index 4f9369f..0000000 --- a/bin/show-keybindings +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -# -# A script to display Hyprland keybindings defined in your configuration -# using wofi for an interactive search menu. -# - -# --- CONFIGURATION --- -# Set the path to your keybindings file. -# The script will check keybindings in 'hyprland.conf'. -HYPRLAND_CONF="$HOME/.config/hypr/hyprland.conf" - -# --- SCRIPT LOGIC --- - -# Determine which configuration file to use -if [ -f "$HYPRLAND_CONF" ]; then - CONFIG_FILE="$HYPRLAND_CONF" -else - # If no config file is found, show an error in wofi and exit - echo "Error: Configuration file not found." | wofi -dmenu -p "Hyprland Error" - exit 1 -fi - -# Process the configuration file to extract and format keybindings -# 1. `grep` finds all lines starting with 'bind' (allowing for leading spaces). -# 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 '^[[:space:]]*bind' "$CONFIG_FILE" | - sed 's/\#.*//' | - awk -F, '{ - # Remove the "bind... =" part and any surrounding whitespace - sub(/^[[:space:]]*bind[^=]*=[[:space:]]*/, "", $1); - - # Combine the modifier and key (first two fields) - key_combo = $1 " + " $2; - gsub(/^[ \t]+|[ \t]+$/, "", key_combo); # Trim whitespace - - # Reconstruct the command from the remaining fields - action = ""; - for (i = 3; i <= NF; i++) { - action = action $i (i < NF ? "," : ""); - } - gsub(/^[ \t]+|[ \t]+$/, "", action); # Trim whitespace - - # Print only if an action exists - if (action != "") { - printf "%-35s → %s\n", key_combo, action; - } - }' | - sed 's/,$//' | - flock --nonblock /tmp/.wofi.lock -c "wofi -dmenu -i --width 60% --height 70% -p 'Hyprland Keybindings'" diff --git a/default/hypr/bindings.conf b/default/hypr/bindings.conf index b0ec530..f6e321d 100644 --- a/default/hypr/bindings.conf +++ b/default/hypr/bindings.conf @@ -11,10 +11,11 @@ bind = SUPER, O, exec, obsidian -disable-gpu bind = SUPER, slash, exec, $passwordManager bind = SUPER, space, exec, flock --nonblock /tmp/.wofi.lock -c "wofi --show drun --sort-order=alphabetical" + bind = SUPER SHIFT, SPACE, exec, pkill -SIGUSR1 waybar bind = SUPER CTRL, SPACE, exec, ~/.local/share/omarchy/bin/swaybg-next bind = SUPER SHIFT CTRL, SPACE, exec, ~/.local/share/omarchy/bin/omarchy-theme-next -bind = SUPER, K, exec, ~/.local/share/omarchy/bin/show-keybindings +bind = SUPER, K, exec, ~/.local/share/omarchy/bin/omarchy-show-keybindings bind = SUPER, W, killactive,