2

This question already has an answer here:

The original question

Is it possible to override tmux's default behaviour of executing .[z|bash_]profile files on every new session, window and pane?

In other words, I'd like it to only execute only the relevant .[zsh|bash]rc script, i.e. for the new session/window/pane to behave like an xterm or urxvt, not like a tty.

More specifically (edit)

I'd like to avoid changing anything to my .*profile and .*rc scripts. I'm looking for a way to ask tmux to open non-login shells in its new sessions, windows and panes by properly configuring it in .tmux.conf, in order to keep the prior philosophy of putting only actual 'login' instructions on .*profile scripts, as recommended for instance here: What should/shouldn't go in .zshenv, .zshrc, .zlogin, .zprofile, .zlogout?

I am aware on how to circumvent the issue by hacking e.g. .zprofile as was answered to Changing tmux .bash_profile behavior , but the question is of how to do it from .tmux.conf

Secondary question

Why does tmux load the .*profile scripts by default, on every session, window and pane, whereas subshells on any context and all (or at least most) variants of X terminals don't?

Some background information (not necessarily relevant)

I barely started using tmux (only occasionally, for now), but I do have an ever-evolving setup, using zsh as my shell of choice, in which .zprofile expects to be called from a tty and do relevant stuff (like deciding to run startx or not based on whether it's on a laptop and the tty number), the .zshrc script expects to be called from any interactive environment and the .zshenv script expects to be loaded whether on an interactive environment or not.

EDIT: Solution (based on comments below)

Adding the following line to .tmux.conf overrides tmux's behaviour and defaults to starting non-login interactive shells (zsh in this case) on new sessions, windows and panes:

set-option -g default-command zsh

marked as duplicate by jasonwryan, Marco, slm, Anthon, user26112 Oct 21 '13 at 19:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Tmux does not read your .bash_profile, it's the shell that reads it. – Marco Oct 21 '13 at 19:45
  • 1
    See jw013's comment... – jasonwryan Oct 21 '13 at 21:18
  • 2
    .zshrc is evaluated in interactive login and non-logins shells. To only evaluate code in login shells use .zlogin and to change the tmux behaviour to use non-login shells use set-option -g default-command 'zsh'. – Marco Oct 21 '13 at 21:25
  • 1
    @jasonwryan I somehow missed that comment - and in fact it doesn't work as is, sadly, but Marco's variant in the comment above does exactly what I was looking for (the -g is fundamental, apparently - I'll add it to the original comment). – Dalker Oct 21 '13 at 21:30
  • 2
    No problem, I'm glad I could help. And it's good to be persistent and update the original question if the duplicate doesn't actually solve it. Sometimes questions get closed too quickly. But it's still better to improve existing answers than to scatter the information over several questions if they are closely related. – Marco Oct 21 '13 at 21:40

Browse other questions tagged or ask your own question.