#!/usr/bin/env bash # This script visualizes all keybindings in the hyprland config. # It also executes the associated command, if a keybinding is selected. # It uses an Awk script, column -t, and rofi-dmenu to do so. # Furthermore, rofi-dmenu expects the file ~/.config/rofi/keybinds.rasi to exist for theming. # Awk script used for parsing `hyprctl binds` # Basically: # $1 contains submap; if empty replace with Default; also replaces shutdown mode. # $2 contains modmap; parsed and replaced with human-readable modifiers # $3 contains key # $4 contains description awkcommand=' BEGIN { FS="\t" } { # submap if ($1 == "") { submap = "Default" } else { submap = $1 if (submap == "l e s h r ^s") { submap = "Shutdown" } } # modmap parse modmap = $2 mods = "1" if (modmap >= 64) { mods = gensub(/1/, " 1", 1, mods) modmap = modmap - 64 } if (modmap >= 8) { mods = gensub(/1/, "Alt 1", 1, mods) modmap = modmap - 8 } if (modmap >= 4) { mods = gensub(/1/, "Ctrl 1", 1, mods) modmap = modmap - 4 } if (modmap >= 1) { mods = gensub(/1/, "Shift 1", 1, mods) modmap = modmap - 1 } mods = gensub(/1/, "", 1, mods) # output printf "%s,%s%s,%s\n", submap, mods, $3, $4 } ' # get binds binds=$(hyprctl binds -j | jq -r '.[] | select(.description != "") | [.submap, .modmask, .key, .description, .dispatcher, .arg] | @tsv') idx=$(printf "%s" "$binds" | awk -F'\t' "$awkcommand" | column -ts',' | rofi -i -dmenu -p "Keybinds" -config ~/.config/rofi/keybinds.rasi -format d) exit # This is permanently borked i think. # Since hyprland0.55 (the lua update), hyprctl binds no longer provides the actual command # Instead, a pointer to a lua fragment is printed instead, which we can't do anything with. # exit if user does not make a selection. if [[ $idx -eq 0 ]]; then printf "No command selected.\nExiting..\n" exit fi # get line cmdline=$(printf "%s" "$binds" | awk -F'\t' "NR == $idx {printf \"%s %s\", \$5, \$6}") # run hyprctl dispatch $5 $6 (< 5,6 of line not shell script) hyprctl eval $cmdline