Dotfiles preview
Display code, diffs, images, and other content in a tmux pane or popup. Auto-detects nvim/megaterm for floating popups.
install
source · Clone the upstream repo
git clone https://github.com/megalithic/dotfiles
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/megalithic/dotfiles "$T" && mkdir -p ~/.claude/skills && cp -r "$T/home/common/programs/ai/pi-coding-agent/skills/preview" ~/.claude/skills/megalithic-dotfiles-preview && rm -rf "$T"
manifest:
home/common/programs/ai/pi-coding-agent/skills/preview/SKILL.mdsource content
Preview Skill
Display content in a tmux pane or popup next to the pi agent. Supports code files, JSON, markdown, diffs, images, logs, and more.
CRITICAL: Pane Safety Rules
Never kill or disrupt the pane running pi. Before killing, closing, or replacing ANY pane:
- Identify your own pane first:
— this is pi's pane. Never kill it.tmux display-message -p '#{pane_id}' - Before
: Verify X is not pi's pane ID.kill-pane -t X - Before sending keys to any pane: Verify the expected app is actually running there:
# What's running in that pane? tmux display-message -t "$TARGET" -p '#{pane_current_command}' # Confirm visually tmux capture-pane -p -t "$TARGET" -S -3 - Never send keys blindly. If target pane doesn't have the expected process, STOP. Re-discover the correct pane.
- Never assume pane identity persists. User may close, rearrange, or swap panes between your commands. Always re-verify.
Requirements
- Must be running inside tmux
script must be in PATH (installed via dotfiles)preview-ai
Commands
/preview
Display content in a preview pane or popup.
/preview [options] [type] <content>
Options:
- Preview mode:-m, --mode <mode>
,tmux-split
,tmux-float
(default)auto
- Auto-close pane after N seconds--auto-close-after <seconds>
- Explicit delta flag (delta is now the default)--delta
- Show help-h, --help
Modes:
- Side pane (default outside nvim)tmux-split
- Large popup window (default inside nvim/megaterm)tmux-float
- Auto-detect: popup if inside nvim, split otherwiseauto
Content Types:
- JSON content (inline or file path)json
- Markdown content (inline or file path)markdown
- jj diff arguments (e.g., "-r @") - uses deltadiff
- jj log arguments (e.g., "-n 5")log
- Bead task ID - renders with glowbead
- File path to preview with batfile
- Image file path (uses chafa or kitty protocol)image
- Shell command to execute (prefix with "cmd:")cmd
- Auto-detect type (default)auto
Examples:
# Preview JSON /preview json '{"foo": "bar"}' /preview json /path/to/data.json # Preview diffs /preview diff -r @ # Uses delta for diff viewing /preview diff # Current working copy changes # Preview files /preview file ~/.config/nvim/init.lua /preview /tmp/output.log # Auto-detects type # Preview markdown /preview markdown "# Hello World" /preview /path/to/README.md # Preview images /preview image /path/to/screenshot.png # Preview with auto-close /preview --auto-close-after 5 diff # Auto-close after 5 seconds # Preview jj log /preview log -n 10 /preview log -r 'main..' # Explicit mode selection /preview --mode tmux-float diff # Force popup mode /preview -m tmux-split file foo.lua # Force split pane mode
Keyboard Shortcuts
- Quick preview of current diff (equivalent toCtrl+Shift+P
)/preview diff
How It Works
The preview extension wraps the existing
preview-ai bash script which:
-
Auto-detection:
- Inside nvim/megaterm (
set): Uses$NVIM
(large floating window)tmux display-popup - Regular tmux: Uses
(side pane)tmux split-window
- Inside nvim/megaterm (
-
Safe pane management:
- Never renders in the caller's pane
- Only searches current session/window for existing previews
- Reuses existing preview pane (kills and recreates)
-
Content rendering:
- JSON: Uses
for formattingjq - Markdown: Uses
for renderingglow - Diffs: Uses
for syntax-highlighted diff viewingdelta - Images: Uses
for terminal display or kitty protocolchafa - Files: Uses
with syntax highlightingbat - Logs: Uses
with paging disabledjj log
- JSON: Uses
-
Closing the preview:
- Press
orq
to close the preview pane/popupEscape
- Press
Limitations
- Requires tmux (will not work in plain terminal)
- Preview pane is created in current window only
- Large files may take time to render
- Image quality depends on terminal capabilities
Troubleshooting
Error: "Preview requires tmux"
- Solution: Run pi inside a tmux session
Error: "preview-ai failed"
- Check if
is in PATH:preview-aiwhich preview-ai - Check if required tools are installed:
,bat
,glow
,jq
,deltachafa
Preview pane not appearing:
- Check if you're in the correct tmux window
- Try manually:
in a terminalpreview-ai diff
Image preview not working:
- Check if
is installed:chafawhich chafa - Check terminal capabilities for image display
- Try
to see actual outputpreview file /path/to/image.png
Related
- tmux skill - For advanced tmux pane control
- files extension - Browse and manage files in the session
- The underlying bash script~/.dotfiles/bin/preview-ai