libtmux Reference MCP Search
On this page

libtmux.Server.if_shell

View as Markdown

Module
libtmux
Declared in
Server
Package
libtmux
Source
src/libtmux/server.py
if_shell ( self , shell_command : str , tmux_command : str , else_command : str | None = None , background : bool | None = None , target_pane : str | None = None ) None
method [source]
method [source]
if_shell

Execute a tmux command conditionally via $ tmux if-shell.

Examples

>>> server.if_shell('true', 'set -g @if_test yes')
>>> server.cmd('show-options', '-gv', '@if_test').stdout[0]
'yes'
Parameters
  • shell_command ( str ) – Shell command whose exit status determines which tmux command runs.

  • tmux_command ( str ) – Tmux command to run if *shell_command* succeeds (exit 0).

  • else_command ( str | None ) – Tmux command to run if *shell_command* fails (non-zero exit).

  • background ( bool | None ) – Run the shell command in the background (-b flag).

  • target_pane ( str | None ) – Target pane for format expansion (-t flag).

0 declared, 0 inherited

Esc

Type to search.