3

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
Dalker
  • 1,622
  • 2
    Tmux does not read your .bash_profile, it's the shell that reads it. – Marco Oct 21 '13 at 19:45
  • @Marco : then why do the shells within new tmux sessions, windows and panes behave like login shells, whereas the shells inside a new xterm don't and other subshells don't? – Dalker Oct 21 '13 at 20:48
  • regarding duplicate question : I did find http://unix.stackexchange.com/questions/61719/changing-tmux-bash-profile-behavior while searching before, but I don't want to test for tmux from within my .*profile scripts, but rather to change something on .tmux.conf so that shells in tmux don't read those scripts. Will edit question accordingly. – Dalker Oct 21 '13 at 20:52
  • 1
  • 4
    .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
  • 1
    @Marco Your last comment actually solved my problem perfectly. Thanks a lot! And sorry for the (mostly) duplicate question... – Dalker Oct 21 '13 at 21:31
  • 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

0 Answers0