I have fixed a, b, c sessions - their name won't be changed and already auto created when I start tmux.

I'd like to auto run a command in the event of creating new pane or new window in a session that isn't a or b or c.

  • Do you want the command to run in the new pane/window, instead of the usual shell? Or should it run in the background, as well as the shell that appears in the window? It would help if you could show an example of the command you want to run, and what you've tried so far. – JigglyNaga Jan 11 at 15:24
  • Command run in the new pane, shell is zsh - same for new window, e.g: the event is to run ssh command to a specific host, nothing more. @JigglyNaga – Tuyen Pham Jan 11 at 15:29

Create a simple script that's run for every new shell (eg. by calling it from your .profile). It should test which Tmux session it's in (if it's in one at all) and only run the relevant command if it's in one other than a, b or c:


if [ -z "$TMUX" ] ; then
        # not in tmux session

TMUX_SESSION=$(tmux display-message -p '#{session_name}')

case "$TMUX_SESSION" in "a"|"b"|"c")
        exit ;;
        ssh machinename command &
  • Thanks, put in .profile should work. But what about solution to re-map key that create new pane/window? - that totally won't depend on .profile. – Tuyen Pham Jan 12 at 8:55
  • @TuyenPham You didn't specify in the question that you needed it to be a keybinding. Define exactly what you want the keybinding to do, and it should be straightforward to find the tmux command(s) to do so. – JigglyNaga Jan 12 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.