-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathextract-tmux-commands.sh
More file actions
executable file
·43 lines (35 loc) · 1.41 KB
/
extract-tmux-commands.sh
File metadata and controls
executable file
·43 lines (35 loc) · 1.41 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
#!/usr/bin/env bash
# Extract tmux command entries from cmd-*.c files
# Usage: extract-tmux-commands.sh [tmux-source-dir]
# Output: command_name|alias|getopt_string|target_type
#
# Parses cmd_entry structs to enumerate all tmux commands with their
# flags and target types.
set -euo pipefail
TMUX_DIR="${1:-$HOME/study/c/tmux}"
if [[ ! -d "$TMUX_DIR" ]]; then
echo "Error: tmux source dir not found at $TMUX_DIR" >&2
exit 1
fi
# Process each cmd-*.c file (skip internal files)
for f in "$TMUX_DIR"/cmd-*.c; do
base=$(basename "$f" .c)
case "$base" in
cmd-parse|cmd-queue|cmd-find) continue ;;
esac
# Use perl for reliable multi-field extraction from cmd_entry structs
perl -0777 -ne '
while (/const\s+struct\s+cmd_entry\s+\w+\s*=\s*\{(.*?)\n\};/gs) {
my $block = $1;
my ($name, $alias, $args, $target) = ("", "-", "", "none");
$name = $1 if $block =~ /\.name\s*=\s*"([^"]+)"/;
$alias = $1 if $block =~ /\.alias\s*=\s*"([^"]+)"/;
$args = $1 if $block =~ /\.args\s*=\s*\{\s*"([^"]*)"/;
$target = "pane" if $block =~ /CMD_FIND_PANE/;
$target = "window" if $block =~ /CMD_FIND_WINDOW/;
$target = "session" if $block =~ /CMD_FIND_SESSION/;
$target = "client" if $block =~ /CMD_FIND_CLIENT/;
print "$name|$alias|$args|$target\n" if $name;
}
' "$f"
done | sort