#!/usr/bin/env bash # rice-keys - searchable cheat sheet of every keybinding, read from sxhkdrc. # A "## Section" line groups bindings; a "# text" line right above a hotkey # describes it. set -uo pipefail rc="${XDG_CONFIG_HOME:-$HOME/.config}/sxhkd/sxhkdrc" dim=$(rice-theme get dim) accent=$(rice-theme get accent) pretty() { sed -E 's/@//g; s/\{_,/{/g; s/\b(super|ctrl|shift|alt)\b/\u\1/g; s/XF86Audio/Media /g; s/Print/PrtSc/g' } escape() { sed 's/&/\&/g; s//\>/g'; } awk ' /^## / { section = substr($0, 4); next } /^# / { desc = substr($0, 3); next } /^$/ { desc = ""; next } /^[^#[:space:]]/ && desc != "" { printf "%s\t%s\t%s\n", section, $0, desc; desc = "" } ' "$rc" | while IFS=$'\t' read -r section keys desc; do printf '%-30s %s ยท %s\n' \ "$accent" "$(pretty <<<"$keys" | escape)" "$(escape <<<"$desc")" "$dim" "$(escape <<<"$section")" done | rofi -dmenu -i -markup-rows -no-custom -theme "$HOME/.config/rofi/menu.rasi" -p "Keybindings" \ -theme-str 'window { width: 900px; } listview { lines: 16; }' >/dev/null