#!/usr/bin/env zsh
# ── cheats.zsh : the index of every search cheat card ────────────────────────
# One command to remember which card exists. Each tool's card lives in its own
# module (fzf.zsh, grep.zsh, ripgrep.zsh, zgrep.zsh, strings.zsh, locate.zsh).
# cheats static text index (below)
# fcheats fuzzy PICKER — live-preview every card, Enter prints it
# consistency alias: rg gets a `rg-cheat` too (its card is the grep↔rg one)
alias rg-cheat='grephelp'
# where the card modules live (each card renders self-contained from its module)
_CHEAT_DIR="${ZDOTDIR:-$HOME/.dotfiles}/config"
cheats() {
print -P ""
print -P "%F{#9ccfd8}▰▰▶ SEARCH TOOLKIT — CHEAT CARD INDEX%f"
print -P "%F{#908caa}──────────────────────────────────────────────────────────────%f"
print -P "%F{#f6c177} pick by the question you're asking%f"
print -P " %F{#e0def4}fzf-cheat%f pick anything interactively (fuzzy) %F{#908caa}fzf%f"
print -P " %F{#e0def4}search%f grep ↔ rg translation, side by side %F{#908caa}grep/rg%f"
print -P " %F{#e0def4}grep-cheat%f classic/portable text search, full ref %F{#908caa}grep%f"
print -P " %F{#e0def4}rg-cheat%f ripgrep — the fast daily driver %F{#908caa}rg%f"
print -P " %F{#e0def4}zgrep-cheat%f search inside .gz/.xz/.bz2/.zst %F{#908caa}zgrep%f"
print -P " %F{#e0def4}strings-cheat%f readable text out of binaries %F{#908caa}strings%f"
print -P " %F{#e0def4}locate-cheat%f instant filename search (indexed) %F{#908caa}plocate%f"
print -P "%F{#908caa}──────────────────────────────────────────────────────────────%f"
print -P "%F{#f6c177} rule of thumb%f"
print -P " name of a FILE? %F{#e0def4}fd%f (live) · %F{#e0def4}locate%f (indexed) · %F{#e0def4}ff%f (fuzzy)"
print -P " …and acting on them? %F{#e0def4}find-cheat%f · every command card: %F{#e0def4}xcheats%f"
print -P " TEXT inside files? %F{#e0def4}rg%f (fast) · %F{#e0def4}grep%f (portable) · %F{#e0def4}fif%f (live/fuzzy)"
print -P " inside archives? %F{#e0def4}zgrep%f or %F{#e0def4}rg -z%f"
print -P " inside binaries? %F{#e0def4}strings | grep%f"
print -P "%F{#908caa} fuzzy pickers: %f%F{#e0def4}fcheats%f%F{#908caa} (search tools) · %f%F{#e0def4}xcheats%f%F{#908caa} (EVERY tool you own)%f"
}
alias cheatsheet='cheats'
alias cheat-index='cheats'
# ── fcheats : fuzzy-pick a cheat card, live preview, Enter prints it ─────────
# Left column = the cards. Preview pane renders the highlighted card in colour
# (a throwaway zsh sources just that card's module). Enter prints the full card
# to the terminal so it stays in your scrollback.
fcheats() {
(( $+commands[fzf] )) || { print -u2 "fcheats: needs fzf"; return 1 }
local dir="$_CHEAT_DIR" sel fn mod
# each row: visible-label \t module-path \t function-name
sel=$(
print -rl -- \
"fzf pick anything interactively (fuzzy)"$'\t'"$dir/fzf.zsh"$'\t'"fzhelp" \
"grep portable text search (GNU grep)"$'\t'"$dir/grep.zsh"$'\t'"grepcheat" \
"ripgrep fast daily driver · grep↔rg card"$'\t'"$dir/ripgrep.zsh"$'\t'"grephelp" \
"zgrep search inside compressed files"$'\t'"$dir/zgrep.zsh"$'\t'"zgrepcheat" \
"strings readable text out of binaries"$'\t'"$dir/strings.zsh"$'\t'"strcheat" \
"locate instant filename search (indexed)"$'\t'"$dir/locate.zsh"$'\t'"loccheat" \
"★ ALL master index + rule of thumb"$'\t'"$dir/cheats.zsh"$'\t'"cheats" |
fzf --ansi --delimiter=$'\t' --with-nth=1 \
--prompt='cheat> ' --pointer='▶' --cycle \
--header='enter = print card · ↑↓ browse · shift-↑↓ scroll preview · esc quit' \
--preview='zsh -c "source {2} 2>/dev/null; {3}"' \
--preview-window='up,72%,border-bottom,wrap'
) || return
[[ -n $sel ]] || return
fn=${sel##*$'\t'} # function name = after the last tab
if (( $+functions[$fn] )); then # already loaded in this shell → call it
$fn
else # fallback: render from its module
mod=${${sel%$'\t'*}##*$'\t'}
zsh -c "source ${(q)mod} 2>/dev/null; $fn"
fi
}
alias cheats-fzf='fcheats'
alias fcheat='fcheats'
# ── xcheats : fuzzy-pick from EVERY cheat card you own ───────────────────────
# The search tools (fzf/grep/…) PLUS the whole x-family toolkit — tarx, gpgx,
# injx, revx, the aenx pentest facets, media/file utils, all of it. It's the
# "what tools do I even have" index. Preview renders the highlighted card in
# colour via `card-render`; Enter prints the full card. Auto-discovers any
# new `~/.local/bin/*-cheat` you add, so the list stays current.
# one-liners, curated (fall back to the tool name for anything newly discovered)
typeset -gA _cheat_desc=(
# version control
jj 'jujutsu VCS — the working copy IS a commit'
# search toolkit (zsh function cards)
fzf 'fuzzy-pick anything · files, lines, procs'
grep 'portable text search (GNU grep)'
rg 'ripgrep — fast recursive text search'
zgrep 'grep inside .gz/.xz/.bz2/.zst'
strings 'readable text out of binaries'
locate 'instant filename search (indexed)'
# aenx — Attacking Enterprise Networks + its facets
aenx 'Attacking Enterprise Networks — parent toolkit'
adx 'Active Directory attack chain (aenx: ad)'
reconx 'recon & enumeration (aenx: recon)'
servicex 'service-specific attacks (aenx: service)'
webx 'web recon & attack (aenx: web)'
winx 'Windows post-exploitation (aenx: windows)'
smbx 'SMB · WinRM · RDP assessment (aenx: smb)'
payloadx 'payload generation (aenx: payload)'
pivotx 'pivoting & tunneling (aenx: pivot)'
ssh 'SSH — keys, transfers, assessment, pivots and tunnels'
# standalone offensive
ffufx 'calibrated web fuzzing (ffuf)'
injx 'command-injection payloads & tricks'
readx 'file-read / LFI primitives & loot'
revx 'reverse shells + listeners'
wshx 'web-shell connect / interact'
pentest 'master index of the pentest wrappers'
# text cleaning
waterx 'watermark toolkit umbrella (wmx + pdfx)'
wmx 'strip AI watermarks/tells out of text'
pdfx 'strip AI watermarks out of PDFs (wmx for PDFs)'
# crypto / files
gpgx 'GPG — encrypt · sign · hash · keys'
tarx 'archive · compress · encrypt · ship'
rsx 'rsync — copy · preview · mirror · SSH transfers'
rcx 'rclone, dressed — upload · detached jobs · verify'
rclone 'cloud folders — Google Drive / pCloud, mount · copy · verify'
gocryptfs 'encrypted folders / filesystem'
# media / house-keeping
gamex 'run Windows .exe files and games (wine/Proton)'
mpv 'mpv video player — every default key binding'
imgx 'images — compress · resize · convert'
vidx 'video — trim · crop · convert · compress'
webget 'browser-aware curl/wget, escalates to ytget/galx'
ytget 'media / YouTube downloader'
galx 'grab every image off a page / gallery (gallery-dl)'
sitex 'pull a whole site down — pages, assets, structure'
dcx 'export Discord servers / channels / DMs'
tagx 'file tagging · renaming · organizing'
mullvad 'Mullvad VPN control'
dnsx 'DNS: flush the cache, ask who answered, prove blocking'
# dev
ghx 'GitHub repos from the terminal (gh, dressed)'
glx 'GitLab repos from the terminal (glab, dressed)'
# backup
bakx 'bank up NetrunnerVault + dotfiles — jj commit + push, long-hand'
# archives & crypto — the raw commands the x-family wrappers drive
tar 'GNU tar — create, extract, compress, preserve, ship'
gpg 'GnuPG — symmetric, keys, sign, verify, agent'
archive 'zip · 7z · zstd/xz/gzip · bsdtar — pick and drive the format'
# core linux — the commands themselves
find 'find(1) — walk the tree and act on what matches'
chmod 'permissions · ownership · special bits · ACLs'
awk 'fields, patterns and small programs over text'
sed 'substitute, delete and edit streams in place'
cat 'reading files — cat, head, tail, less, bat, xxd'
echo 'echo vs printf — output, escapes and quoting'
text 'the text pipeline — cut, sort, uniq, tr, wc, column'
proc 'processes — ps, kill, jobs, lsof, what is using this'
service 'watch → find → kill: pkill, killall, fuser, ports, systemd units'
systemd 'systemctl, journalctl, units and timers'
disk 'disks and space — df, du, lsblk, mount'
# media
yt-dlp 'yt-dlp directly — formats, cookies, referer, every flag'
)
# preferred display order; discovered-but-unlisted cards get appended after
typeset -ga _cheat_order=(
jj
fzf grep rg zgrep strings locate
aenx adx reconx servicex webx winx smbx payloadx pivotx
ssh ffufx injx readx revx wshx pentest
waterx wmx pdfx
gpgx tarx rsx rcx rclone gocryptfs
tar gpg archive
imgx vidx mpv webget ytget galx sitex dcx tagx mullvad dnsx ghx glx gamex
bakx
find chmod awk sed cat echo text proc service systemd disk
yt-dlp
)
xcheats() {
(( $+commands[fzf] )) || { print -u2 "xcheats: needs fzf"; return 1 }
command -v card-render >/dev/null 2>&1 || { print -u2 "xcheats: needs ~/.local/bin/card-render"; return 1 }
local bindir="$HOME/.local/bin" key desc sel
local -a search=(fzf grep rg zgrep strings locate) rows
local -A seen
_exists() { # search cards always; tool cards need a <key>-cheat on disk
[[ ${search[(Ie)$1]} -gt 0 ]] || [[ -x "$bindir/$1-cheat" ]]
}
_row() { # $1=key → append " key desc \t key"
local k=$1 d=${_cheat_desc[$1]:-'cheat card'}
rows+=( "$(printf '%-10s %s' "$k" "$d")"$'\t'"$k" )
seen[$k]=1
}
for key in $_cheat_order; do _exists "$key" && _row "$key"; done
# future-proof: any *-cheat script not already in the curated order
for f in "$bindir"/*-cheat(N); do
key=${${f:t}%-cheat}
[[ -n ${seen[$key]} ]] || _row "$key"
done
sel=$(print -rl -- "$rows[@]" |
fzf --delimiter=$'\t' --with-nth=1 \
--prompt='tool> ' --pointer='▶' --cycle \
--header='enter = print card · type to filter · shift-↑↓ scroll preview · esc quit' \
--preview='card-render {2}' \
--preview-window='up,75%,border-bottom,wrap') || return
[[ -n $sel ]] || return
card-render "${sel##*$'\t'}"
}
alias xcheat='xcheats'
alias tools='xcheats'