Skip to content

tmux🔗

tmux is a terminal multiplexer.

Scripting with tmux🔗

Check if running inside a tmux session🔗

If tmux is version 3.2 or newer the environment variable TERM_PROGRAM is set:

if [ "$TERM_PROGRAM" = tmux ]
then
  echo "Inside a tmux session"
else
  echo "Outside a tmux session"
fi

send-keys🔗

The command send-keys has the following syntax:

tmux send-keys -t '{session}:{window}.{pane}' {command} ENTER

The target can be shorted as -t ':.!', which means:

  • last active session
  • last active window
  • previously selected pane

Usage with new-window:

tmux new-window -c "${dir}" -n "${name}"
tmux send-keys -t ':.' "${EDITOR}" ENTER

Usage with new-session:

tmux new-session -d
tmux send-keys -t ':.' "${EDITOR}" ENTER
tmux attach-session -t ":"

Current special key bindings🔗

  • Ctrl+A V - split pane vertically (same directory)
  • Ctrl+A H - split pane horizontally (same directory)