zaneyos/modules/home/scripts/keybinds.nix

67 lines
2.1 KiB
Nix
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ pkgs }:
pkgs.writeShellScriptBin "list-keybinds" ''
# check if rofi is already running
if pidof rofi > /dev/null; then
pkill rofi
fi
msg='☣️ NOTE ☣️: Clicking with Mouse or Pressing ENTER will have NO function'
# Parse keybind entries from the Nix config and format for rofi display
BIND_NIX="$HOME/zaneyos/modules/home/hyprland/binds.nix"
if [[ -f "$BIND_NIX" ]]; then
display_keybinds=$(
${pkgs.gawk}/bin/awk '
# Track when we enter any keybind array
/noctaliaBind/ { in_block = 1; next }
/rofiBind/ { in_block = 1; next }
/bindd[ ]*=/ && /\[/ { in_block = 1; next }
in_block {
# Check for end of array
if (/^[ ]*\]/) {
in_block = 0
next
}
# Extract quoted string from line
if (match($0, /"([^"]+)"/, arr)) {
line = arr[1]
# Split by comma to get: mods, key, desc, action, params
n = split(line, parts, ",")
if (n >= 3) {
# Extract and trim each part
mods = parts[1]
key = parts[2]
desc = parts[3]
gsub(/^[ \t]+|[ \t]+$/, "", mods)
gsub(/^[ \t]+|[ \t]+$/, "", key)
gsub(/^[ \t]+|[ \t]+$/, "", desc)
# Build display keybind
if (mods != "" && key != "") {
display = mods " + " key
gsub(/\$modifier/, "SUPER", display)
gsub(/ +/, " ", display)
# Output: "KEYBIND: Description"
if (desc != "") {
printf "%s: %s\n", display, desc
}
}
}
}
}
' "$BIND_NIX"
)
else
# Fallback: Show error message
display_keybinds="Error: Keybinds file not found at $BIND_NIX"
fi
# use rofi to display the keybinds with the modified content
echo "$display_keybinds" | rofi -dmenu -i -config ~/.config/rofi/config-long.rasi -mesg "$msg"
''