Remembering every Sway shortcut is tough. I wrote a small script that parses your Sway config, displays all bindsym shortcuts 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 all
bindsym …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 through
swaymsg
Dependencies
- sway (for
swaymsg) - 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.sh and make it executable.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#!/usr/bin/env bash # This script lists Sway keybindings from the Sway config file and allows the user to select one via rofi dmenu. # When a keybinding is selected, it executes the associated command. CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/sway/config" # Check if config file exists if [[ ! -f "$CONFIG_FILE" ]]; then notify-send "Sway Keybindings" "Config file not found: $CONFIG_FILE" -u critical exit 1 fi # Parse keybindings from config file # Format: "Mod+Key → Command description" keybindings=$(grep -E '^\s*bindsym' "$CONFIG_FILE" | \ grep -v '^[[:space:]]*#' | \ sed 's/^\s*bindsym\s*//' | \ awk '{ # Remove trailing inline comments sub(/\s+#.*$/, "") # Skip leading flags like --release, --locked, etc. i = 1 while (i <= NF && $i ~ /^--/) { i++ } if (i > NF) next # Extract the key combination keys = $i; i++ # Extract the command (remaining fields) cmd = "" for (j = i; j <= NF; j++) { if (j > i) cmd = cmd " " cmd = cmd $j } # Format: "Key → Command" # Clean up common modifier names for better display gsub(/\$mod/, "Mod", keys) gsub(/Shift/, "⇧", keys) gsub(/Control/, "Ctrl", keys) gsub(/\+/, " + ", keys) printf "%-35s → %s\n", keys, cmd }') # Show in rofi and get selection selected=$(echo "$keybindings" | rofi -i -dmenu -p "Sway Shortcuts" -theme-str 'window {width: 60%;}') # If something was selected, extract and execute the command if [[ -n "$selected" ]]; then # Extract the command part (after the arrow) command=$(echo "$selected" | sed 's/^[^→]*→\s*//') if [[ -n "$command" ]]; then # Execute the command through swaymsg swaymsg "$command" fi fi |
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:
grep -E '^\s*bindsym'finds all bindsym lines (ignoring leading whitespace)grep -v '^[[:space:]]*#'ignores full-line commentssed 's/^\s*bindsym\s*//'strips the leadingbindsymawksplits 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 --release or --locked before 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 to swaymsg. That means anything you can put after bindsym (like exec …, 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.:
|
1 2 |
bindsym $mod+slash exec ~/.local/bin/rofi-sway-keybindings.sh |
Tip: the window is set to 60% width for readability; tweak it via -theme-str if you prefer.
Nice touches in the UI
- Replaces
$modwithMod - Shows
Shiftas⇧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):


