Browse and run your Sway keybindings with Rofi

Remembering everySwayshortcut is tough. I wrote a small script that parses your Sway config, displays allbindsymshortcuts in a clean, searchable list via Rofi, and executes the command associated with whichever one you select.

It’s fast, keyboard-friendly, and great for discovery: “What did I bind to Mod + Shift + P again?” Now you can search, see, and execute it.

What the script does

  • Reads your Sway config from$XDG_CONFIG_HOME/sway/config(or~/.config/sway/config)
  • Finds allbindsym …lines
  • Formats each entry nicely, e.g.

Mod + Return → exec alacritty

  • Shows the list in a wide Rofi dmenu
  • When you select an entry, it executes the associated command throughswaymsg

Dependencies

  • sway (forswaymsg)
  • rofi
  • awk, sed, grep (standard on most distros)
  • notify-send (optional – shows an error if the config isn’t found)

The script

Save this as~/.local/bin/rofi-sway-keybindings.shand make it executable.

How it works

The core of the script is a small text-processing pipeline that reads the config and renders a nice two-column list for Rofi:

  1. grep -E '^\s*bindsym'finds all bindsym lines (ignoring leading whitespace)
  2. grep -v '^[[:space:]]*#'ignores full-line comments
  3. sed 's/^\s*bindsym\s*//'strips the leadingbindsym
  4. awksplits the line into (and does some cleanup):

–keys: the first token (e.g.$mod+Return)
–cmd: the rest of the line (e.g.exec alacritty)

It also strips trailing inline comments (after#) and skips bindsym flags like--releaseor--lockedbefore reading the key. Finally, it prettifies modifiers and prints a fixed-width column so the arrows line up.

Rofi presents that list with-dmenu. When you pick one, the script extracts the command part (after→) and sends it toswaymsg. That means anything you can put afterbindsym(likeexec …,workspace …,kill, etc.) will run on demand.

Usage

  • Run the script from a terminal:rofi-sway-keybindings.sh
  • Or bind it to a key in your Sway config, e.g.:

Tip: the window is set to 60% width for readability; tweak it via-theme-strif you prefer.

Nice touches in the UI

  • Replaces$modwithMod
  • ShowsShiftas⇧andControlasCtrl
  • Adds spacing around+so chords read clearly:Mod + ⇧ + q
  • Aligns the left column to 35 characters for a tidy two-column look

Why this is handy

  • Onboarding: perfect for new setups or when you come back after a while
  • Discovery: search by key or by command to find what you already have
  • Launcher: use it as a programmable “cheat sheet” that also runs things

Here are some screenshots (including filtering):

4 thoughts on “Browse and run your Sway keybindings with Rofi”

      1. Lorenzo BettiniPost author

        @joekamprad yes please, that’s be great!
        If you could please add my name and a link to this article 🙂

Leave a Reply

This site uses Akismet to reduce spam.Learn how your comment data is processed.