# Function to parse modmask into readable modifier names def parse_modmask [modmask: int] { let modifiers = [ { mask: 64, name: "SUPER" }, { mask: 1, name: "SHIFT" }, { mask: 4, name: "CTRL" }, { mask: 8, name: "ALT" } ] let active_mods = $modifiers | where { |mod| ($modmask | bits and $mod.mask) != 0 } | get name if ($active_mods | is-empty) { "None" } else { $active_mods | str join "+" } } # Function to format key for display def format_key [key: string, mouse: bool] { if $mouse { $key | str replace "mouse:" "MOUSE_" } else { $key | str upcase } } # Main function to process binds and show fuzzel menu def main [] { # Get binds from hyprctl let binds = (hyprctl binds -j | from json) # Parse binds into a formatted list for fuzzel let formatted_binds = $binds | each { |bind| let mods = (parse_modmask $bind.modmask) let key = (format_key $bind.key $bind.mouse) let display = $"($mods) + ($key) -> ($bind.dispatcher): ($bind.arg)" { display: $display, arg: $bind.arg, dispatcher: $bind.dispatcher } } # Create a temporary file for fuzzel let temp_file = (mktemp -t hypr_binds.XXXXXX | str trim) $formatted_binds | each { |b| $b.display } | str join "\n" | save -f $temp_file # Show fuzzel menu and get selection let selection = (cat $temp_file | fuzzel --dmenu --prompt "Keybindings: " | str trim) rm $temp_file # Find the selected binding and execute its arg if ($selection | is-not-empty) { let selected_bind = ($formatted_binds | where display == $selection | first) if ($selected_bind | is-not-empty) { if $selected_bind.dispatcher == "exec" { run-external ($selected_bind.arg | split row ' ') } else { hyprctl dispatch $selected_bind.dispatcher $selected_bind.arg } } } }