Skip to main content
Back to Commands
MiscellaneousN/A (configuration command)

if-shell

Short form: if

Run the first command if shell-command succeeds, otherwise the optional second command. With -F, no shell runs and the condition is a format that is true unless empty or zero.

Synopsis

bash
tmux if-shell [-bF] [-t target-pane] shell-command command [command]

Options

FlagDescription
-bRun shell-command in the background (don't block)
-FTreat the condition as a format, not a shell command
-t target-paneTarget pane for the commands

Examples

Source a file only if it exists

bash
if-shell 'test -f ~/.tmux.local' 'source ~/.tmux.local'

Apply host-specific config without spawning a shell

bash
if-shell -F '#{==:#{host},laptop}' 'source ~/.tmux-laptop.conf'

Default Keybinding

N/A (configuration command)

Default prefix is Ctrl+b

Pro Tips

  • Use -F with formats to branch without the cost of a shell
  • Great for making one .tmux.conf portable across machines