/ de-omarchy / bin / omarchy-menu-tmux-keybindings
swadhinbiswas Initial de-omarchy: Omarchy UI layer for Arch-based distros · 8/22/2026
9f393b2
138 lines · 3.4 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash

# omarchy:summary=Display annotated Tmux keybindings using an interactive search menu.
# omarchy:args=[--print|-p] [--config <path>]

print_only=false
config_file="${TMUX_CONF:-$HOME/.config/tmux/tmux.conf}"

while (($#)); do
  case "$1" in
    --print|-p)
      print_only=true
      ;;
    --config)
      shift
      config_file="$1"
      ;;
    *)
      config_file="$1"
      ;;
  esac

  shift
done

if [[ ! -f $config_file ]]; then
  default_config="$OMARCHY_PATH/config/tmux/tmux.conf"

  if [[ -f $default_config ]]; then
    config_file="$default_config"
  else
    echo "Tmux config not found: $config_file" >&2
    exit 1
  fi
fi

output_keybindings() (
  set -o pipefail
  socket_dir=$(mktemp -d)
  socket="$socket_dir/tmux"
  trap 'tmux -S "$socket" kill-server >/dev/null 2>&1 || true; rm -f "$socket"; rmdir "$socket_dir" 2>/dev/null || true' EXIT
  tmux -S "$socket" -f /dev/null start-server \; \
    unbind-key -a -T prefix \; \
    unbind-key -a -T root \; \
    unbind-key -a -T copy-mode \; \
    unbind-key -a -T copy-mode-vi \; \
    source-file "$config_file" \; \
    show-options -g prefix \; \
    show-options -g prefix2 \; \
    list-keys -aN -T prefix -P "prefix" \; \
    list-keys -aN -T root -P "root" \; \
    list-keys -aN -T copy-mode-vi -P "copy-mode-vi" | awk '
function key_part_text(part, is_modifier, part_count) {
  gsub(/^\\/, "", part)

  if (is_modifier && part == "C") return "CTRL"
  if (is_modifier && part == "M") return "ALT"
  if (is_modifier && part == "S") return "SHIFT"
  if (part == "Space") return "SPACE"
  if (part == "BSpace") return "BACKSPACE"
  if (part == "BTab") return "SHIFT + TAB"
  if (part == "PPage") return "PAGE UP"
  if (part == "NPage") return "PAGE DOWN"
  if (part == "DC") return "DELETE"
  if (part == "IC") return "INSERT"
  if (part_count == 1 && part ~ /^[a-z]$/) return part

  return toupper(part)
}

function key_text(key, parts, count, i, part, text) {
  gsub(/\\/, "", key)
  count = split(key, parts, "-")
  text = ""

  for (i = 1; i <= count; i++) {
    part = key_part_text(parts[i], i < count, count)
    text = text (text == "" ? "" : " + ") part
  }

  return text
}

function table_text(table) {
  if (table == "copy-mode-vi") return "COPY MODE"
  if (table == "copy-mode") return "COPY MODE"
  if (table == "prefix") return "PREFIX"

  gsub(/-/, " ", table)
  return toupper(table)
}

$1 == "prefix" && NF == 2 { prefix = $2; next }
$1 == "prefix2" && NF == 2 { prefix2 = $2; next }

{
  if (!header_printed) {
    prefix_description = key_text(prefix)

    if (prefix2 != "" && prefix2 != "None") {
      prefix_description = prefix_description " / " key_text(prefix2)
    }

    printf "%-32s → %s\n", "PREFIX", prefix_description
    header_printed = 1
  }

  table = $1
  key = $2
  note = $0
  sub(/^[^ ]+ +[^ ]+ +/, "", note)

  if (table == "root") {
    combo = key_text(key)
  } else {
    combo = table_text(table) " + " key_text(key)
  }

  printf "%-32s → %s\n", combo, note
}'
)

if [[ $print_only == "true" ]]; then
  output_keybindings
  exit 0
fi

records=$(output_keybindings)

monitor_height=$(hyprctl monitors -j 2>/dev/null | jq -r '.[] | select(.focused == true) | .height' 2>/dev/null)

if [[ ! $monitor_height =~ ^[0-9]+$ ]] || ((monitor_height <= 0)); then
  monitor_height=900
fi

menu_height=$((monitor_height * 40 / 100))
printf '%s\n' "$records" | omarchy-menu-select 'Tmux keybindings' -- --width 800 --height "$menu_height" >/dev/null || true