How can I make tmux use my default shell?

150,822

Solution 1

set-option -g default-shell /bin/zsh

in ~/.tmux.conf or /etc/tmux.conf. Works on Fedora.

You can reload the config with <leader>: source-file <conf file> e.g.

<C-b>: source-file ~/.tmux.conf

You would need to do it for every tmux instance. Otherwise you may restart tmux with killall tmux; tmux

Solution 2

First, ensure your default shell is set properly to zsh by running this in your command line:

chsh -s $(`which zsh`) $USER

Placing the following in your ~/.tmux.conf is a more robust option for any shell.

set-option -g default-shell $SHELL

Solution 3

For MacOS users, drop this line in the bottom of your ~/.tmux.conf

set-option -g default-command "reattach-to-user-namespace -l zsh"

After you add that, kill and restart your tmux server and all should work.

Solution 4

tmux appears to use the SHELL environment variable, so the following should work:

SHELL=/usr/bin/zsh tmux

or

env SHELL=/usr/bin/zsh tmux

Solution 5

If you want to force tmux to use the same shell as specified in your environment variable, you could use:

# force SHELL ENV variable as shell
set-option -g default-shell ${SHELL}

in your ~/.tmux.conf or /etc/tmux.conf.

To get the change to actually take effect, you may need to tmux kill-server and then tmux to restart tmux.

Share:
150,822

Related videos on Youtube

re5et
Author by

re5et

Updated on September 17, 2022

Comments

  • re5et
    re5et over 1 year

    On a new setup, tmux is using bash instead of my default (zsh).

    How can I force it to use zsh?

    • re5et
      re5et about 13 years
      figured it out. Can set the following in tmux config: set -g default-command /bin/zsh set -g default-shell /bin/zsh
    • Nicholas Riley
      Nicholas Riley about 12 years
      FWIW, you don't need to set default-command if you've set default-shell.
  • Anup Dey
    Anup Dey over 11 years
    If this doesn't work for you then make sure you've restart tmux. Seems obvious but took me a good hour to figure out!
  • js-coder
    js-coder over 11 years
    BTW: Restarting tmux means killall tmux; tmux. Took me quite a while to figure out.
  • ДМИТРИЙ МАЛИКОВ
    ДМИТРИЙ МАЛИКОВ almost 11 years
    Configs could be reloaded without killing a server: bind R source-file ~/.tmux.conf \; display-message " Config reloaded..".
  • EhevuTov
    EhevuTov almost 11 years
    I think this answer only works for Mac OS X
  • Keith Smiley
    Keith Smiley over 10 years
    tmux kill-server is the command to end all tmux servers
  • Petr
    Petr over 9 years
    Or simply run tmux source-file ~/.tmux.conf from the command line.
  • Lorenzo
    Lorenzo over 9 years
    @js-coder: to more cleanly kill your tmux server I'd recommend tmux kill-server instead.
  • Jose Alban
    Jose Alban over 8 years
    Although it wasn't the answer the OP asked for, I ended up in this thread and indeed I am on OS X, using this wrapper, and this is the solution I needed; so Thank You!
  • Tommy
    Tommy over 8 years
    how does this differ from set-option -g default-shell ? the above does not seem to work with the Fish shell.
  • dylnmc
    dylnmc almost 8 years
    not sure if it's just a newer version of tmux, but I never had to kill the tmux server or tmux itself. Once you set the option, it should work.
  • Sam Brightman
    Sam Brightman over 7 years
    Not sure why this was down-voted. It appears to be correct: a common problem is using a different shell for e.g. iTerm but leaving login shell as /bin/bash to ensure nothing non-iteractive breaks. iTerm will not set $SHELL to the new shell name (unsure why), and bash initialisation will set it to the login shell if unset at startup. tmux then uses this value if default-shell is not set explicitly.
  • blueyed
    blueyed over 7 years
    Yeah.. maybe env SHELL=/usr/bin/zsh tmux is better? (updated the answer).
  • Mahmoud Al-Qudsi
    Mahmoud Al-Qudsi almost 7 years
    It is unnecessary to set user shell (chsh -s) as tmux offers an option independent of that.
  • loxaxs
    loxaxs over 6 years
    killall not working on zesty. I had to pkill tmux. The processes were named 'tmux: server' and 'tmux: client'.
  • awendt
    awendt over 6 years
    Change zsh to $SHELL to make it work without hard-coding your shell.
  • undefined
    undefined over 6 years
    This is the only answer that worked for me (the tmux kill-server command)
  • DebugXYZ
    DebugXYZ over 5 years
    I thought it was more robust to use the $SHELL variable. But it adds an extra step and confusion so I do prefer the accepted answer.
  • HappyFace
    HappyFace almost 5 years
    This is better than the accepted answer. My zsh is not installed in /bin/zsh.
  • 174140
    174140 over 4 years
    This is a duplicate of answer superuser.com/a/1370909/174140.
  • Ali Amin
    Ali Amin over 4 years
    @john I've used set-option -g instead of set -g. different versions of tmux most probably
  • 174140
    174140 over 4 years
    set is an alias for set-option.
  • dessert
    dessert over 3 years
    Is the double command substitution intended?
  • Community
    Community about 2 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
  • Zach_is_my_name
    Zach_is_my_name about 2 years
    You can find more information on how I meant exactly what I typed in the help center...