Tmux Popup Hacks for Terminal Productivity

News

Popups 101

  • display-popup command basics
  • Sizing: -w (width), -h (height) as percentage or cell count
  • Positioning: -x, -y or -d for current pane center
  • Closing: -E to close on exit, -EE to close on success only
  • Binding to keys: bind + display-popup
# Basic popup running a command
tmux display-popup -w 80% -h 80% -E "command here"

# Popup anchored to current pane
tmux display-popup -d '#{pane_current_path}' -w 80% -h 80% -E "command"

File Browser Popup

Browse and preview files with fzf + bat.

Guix packages: fzf, bat

# fzf file browser with bat preview
tmux display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "fzf --preview 'bat --color=always --style=numbers {}'"

Quick File Editor

Open a file in your editor via fzf, popup closes when you’re done.

# Find and edit a file
tmux display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "fzf --preview 'bat --color=always {}' --bind 'enter:become($EDITOR {})'"

Git Diff Viewer

View diffs with syntax highlighting using git-delta.

Guix packages: git-delta, diff-so-fancy

# Git diff in a popup with delta
tmux display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "git diff | delta | less -R"

# Git log with diff preview
tmux display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "git log --oneline | fzf --preview 'git show {1} | delta'"

Git Status Popup

Quick at-a-glance view of working tree state.

# Simple git status
tmux display-popup -d '#{pane_current_path}' -w 60% -h 60% -E \
  "git status && read -n1"

# Or use fzf to browse changed files with diff preview
tmux display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "git status -s | fzf --preview 'git diff {2} | delta'"

Grep / Search Popup

Search code with ripgrep, preview matches in context with bat.

Guix packages: ripgrep

# Ripgrep + fzf with preview
tmux display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "rg --line-number . | fzf --delimiter : \
    --preview 'bat --color=always --highlight-line {2} {1}' \
    --bind 'enter:become($EDITOR {1} +{2})'"

Keybindings

Wire everything to prefix-key combos in ~/.tmux.conf:

# Prefix-f: file browser
bind f display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "fzf --preview 'bat --color=always --style=numbers {}'"

# Prefix-e: find and edit
bind e display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "fzf --preview 'bat --color=always {}' --bind 'enter:become($EDITOR {})'"

# Prefix-g: git status
bind g display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "git status -s | fzf --preview 'git diff {2} | delta'"

# Prefix-d: git diff
bind d display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "git diff | delta | less -R"

# Prefix-/: search with ripgrep
bind / display-popup -d '#{pane_current_path}' -w 80% -h 80% -E \
  "rg --line-number . | fzf --delimiter : \
    --preview 'bat --color=always --highlight-line {2} {1}' \
    --bind 'enter:become($EDITOR {1} +{2})'"

Useful Links

Subscribe to the System Crafters Newsletter!
Stay up to date with the latest System Crafters news and updates! Read the Newsletter page for more information.
Name (optional)
Email Address