initial commit: tmux cheat sheet alfred workflow
Some checks failed
Build Workflow / build (push) Failing after 6s
Some checks failed
Build Workflow / build (push) Failing after 6s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
77
scripts/parse_manual.sh
Normal file
77
scripts/parse_manual.sh
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build the tmux cheat sheet TSV from curated examples + man page key bindings.
|
||||
# Output format: name\tdescription\tcommand\tshortcut
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
OUT="${SCRIPT_DIR}/../data/tmux_commands.tsv"
|
||||
EXAMPLES="${SCRIPT_DIR}/../data/examples.tsv"
|
||||
TIERS="${SCRIPT_DIR}/../data/tiers.tsv"
|
||||
|
||||
man tmux | col -b > /tmp/tmux_man_raw.txt
|
||||
|
||||
# Extract key bindings from man page, then append curated examples, then sort by tier
|
||||
{
|
||||
# 1. Key bindings from the man page
|
||||
awk '
|
||||
/^DEFAULT KEY BINDINGS/ { in_keys=1; next }
|
||||
in_keys && /^[A-Z][A-Z ]/ && !/^DEFAULT/ { flush(); in_keys=0 }
|
||||
|
||||
function flush() {
|
||||
if (cur_key != "" && cur_desc != "") {
|
||||
shortcut = "{prefix} " cur_key
|
||||
gsub(/C-/, "Ctrl+", shortcut)
|
||||
gsub(/M-/, "Alt+", shortcut)
|
||||
first = cur_desc
|
||||
sub(/\. .*/, ".", first)
|
||||
name = "key-" cur_key
|
||||
gsub(/[[:space:]]/, "-", name)
|
||||
printf "%s\t%s\t\t%s\n", name, first, shortcut
|
||||
}
|
||||
cur_key = ""
|
||||
cur_desc = ""
|
||||
}
|
||||
|
||||
in_keys && /^\t/ && /[^ \t]/ {
|
||||
flush()
|
||||
line = $0
|
||||
gsub(/^[[:space:]]+/, "", line)
|
||||
n = match(line, /\t| +/)
|
||||
if (n > 0) {
|
||||
cur_key = substr(line, 1, n-1)
|
||||
cur_desc = substr(line, n)
|
||||
gsub(/^[[:space:]]+/, "", cur_desc)
|
||||
gsub(/[[:space:]]+$/, "", cur_desc)
|
||||
gsub(/[[:space:]]+$/, "", cur_key)
|
||||
}
|
||||
next
|
||||
}
|
||||
in_keys && /^\t\t/ && cur_key != "" {
|
||||
line = $0
|
||||
gsub(/^[[:space:]]+/, "", line)
|
||||
gsub(/[[:space:]]+$/, "", line)
|
||||
cur_desc = cur_desc " " line
|
||||
next
|
||||
}
|
||||
|
||||
END { flush() }
|
||||
' /tmp/tmux_man_raw.txt
|
||||
|
||||
# 2. Curated examples (name\tdescription\tcommand, no shortcut)
|
||||
awk -F'\t' '{ printf "%s\t%s\t%s\t\n", $1, $2, $3 }' "${EXAMPLES}"
|
||||
|
||||
} | awk -F'\t' '
|
||||
NR == FNR {
|
||||
tier[$1] = $2
|
||||
next
|
||||
}
|
||||
{
|
||||
split($1, parts, /[[:space:]]/)
|
||||
cmd = parts[1]
|
||||
t = (cmd in tier) ? tier[cmd] : 3
|
||||
print t "\t" $0
|
||||
}
|
||||
' "${TIERS}" - | sort -t$'\t' -k1,1n | cut -f2- > "${OUT}"
|
||||
|
||||
count="$(wc -l < "${OUT}" | tr -d ' ')"
|
||||
echo "Wrote ${count} entries to ${OUT}"
|
||||
76
scripts/tmux_search.sh
Executable file
76
scripts/tmux_search.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DATA_FILE="${SCRIPT_DIR}/../data/tmux_commands.tsv"
|
||||
QUERY="${1:-}"
|
||||
PREFIX="${prefix:-Ctrl+b}"
|
||||
|
||||
awk -F'\t' -v query="${QUERY}" -v max=25 -v pfx="${PREFIX}" '
|
||||
BEGIN {
|
||||
n = split(tolower(query), words, /[[:space:]]+/)
|
||||
count = 0
|
||||
printf "{\"items\":["
|
||||
}
|
||||
|
||||
{
|
||||
name = $1; desc = $2; cmd = $3; shortcut = $4
|
||||
if (name == "") next
|
||||
gsub(/{prefix}/, pfx, shortcut)
|
||||
|
||||
blob = tolower(name " " desc " " cmd " " shortcut)
|
||||
for (i = 1; i <= n; i++) {
|
||||
if (index(blob, words[i]) == 0) next
|
||||
}
|
||||
|
||||
if (count >= max) exit
|
||||
|
||||
# Key bindings: title = shortcut + desc, subtitle = empty
|
||||
# Commands: title = desc, subtitle = command
|
||||
if (shortcut != "") {
|
||||
title = shortcut " — " desc
|
||||
subtitle = cmd
|
||||
copy = shortcut
|
||||
} else {
|
||||
title = desc
|
||||
subtitle = cmd
|
||||
copy = cmd
|
||||
}
|
||||
|
||||
# arg = both lines for clipboard
|
||||
if (subtitle != "") {
|
||||
arg = title "\n" subtitle
|
||||
} else {
|
||||
arg = title
|
||||
}
|
||||
|
||||
if (count > 0) printf ","
|
||||
count++
|
||||
|
||||
printf "{\"uid\":\"%s\",", escape(name "-" count)
|
||||
printf "\"title\":\"%s\",", escape(title)
|
||||
printf "\"subtitle\":\"%s\",", escape(subtitle)
|
||||
printf "\"arg\":\"%s\",", escape(arg)
|
||||
printf "\"match\":\"%s\",", escape(name " " desc " " cmd " " shortcut)
|
||||
printf "\"text\":{\"copy\":\"%s\",\"largetype\":\"%s\"},", escape(copy), escape(arg)
|
||||
printf "\"quicklookurl\":\"https://tmuxcheatsheet.com\"}"
|
||||
}
|
||||
|
||||
END {
|
||||
if (count == 0) {
|
||||
printf "{\"uid\":\"no-results\","
|
||||
printf "\"title\":\"No tmux commands found\","
|
||||
printf "\"subtitle\":\"Try a broader query (e.g. split, session, pane, copy)\","
|
||||
printf "\"valid\":false}"
|
||||
}
|
||||
printf "]}"
|
||||
}
|
||||
|
||||
function escape(s) {
|
||||
gsub(/\\/, "\\\\", s)
|
||||
gsub(/"/, "\\\"", s)
|
||||
gsub(/\t/, " ", s)
|
||||
gsub(/\n/, "\\n", s)
|
||||
return s
|
||||
}
|
||||
' "${DATA_FILE}"
|
||||
Reference in New Issue
Block a user