How can I set my default shell to start up tmux












63














I would like my default bash shell to go straight into tmux instead of my always having to type tmux every time.










share|improve this question





























    63














    I would like my default bash shell to go straight into tmux instead of my always having to type tmux every time.










    share|improve this question



























      63












      63








      63


      22





      I would like my default bash shell to go straight into tmux instead of my always having to type tmux every time.










      share|improve this question















      I would like my default bash shell to go straight into tmux instead of my always having to type tmux every time.







      bash shell terminal tmux bashrc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 '15 at 15:16

























      asked Jul 20 '12 at 14:05









      Michael Durrant

      15.7k44114182




      15.7k44114182






















          13 Answers
          13






          active

          oldest

          votes


















          40














          This seems to work...



          https://wiki.archlinux.org/index.php/Tmux#Start_tmux_on_every_shell_login



          Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar:



          [[ $TERM != "screen" ]] && exec tmux





          share|improve this answer



















          • 2




            For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page)
            – Keith Smiley
            Apr 14 '13 at 1:45






          • 2




            This is a bad solution since the TERM might be set to some other value by the user's .tmux.conf file. Better to check whether the TMUX variable is set or not.
            – Kusalananda
            Dec 30 '16 at 13:21



















          79














          @StarNamer's answer is generally accurate, though I typically include the following tests to make sure that (1) tmux exists on the system, (2) we're in an interactive shell, and (3) tmux doesn't try to run within itself:



          if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
          exec tmux
          fi




          References




          • Using bash's command to check for existence of a command - http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_BUILTIN_COMMANDS

          • Why to use command instead of which to check for the existence of commands - https://unix.stackexchange.com/a/85250

          • Using $PS1 to check for interactive shell - https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html

          • Expected state of $TERM environment variable "for all programs running inside tmux" - http://man7.org/linux/man-pages/man1/tmux.1.html#WINDOWS_AND_PANES






          share|improve this answer



















          • 1




            Nice, I have needed command before but didn't realize it existed.
            – Freedom_Ben
            Jun 21 '15 at 0:25










          • I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B edits my .bashrc. Vim can't open for some reason if the above is at the top of the bashrc. I've wrapped the middle line in another if statement, if [ ! -z "$PS1" ]; then...fi (checking that it's running in interactive mode)
            – Louis Maddox
            Aug 2 '15 at 20:03








          • 2




            this exec statement doesn't let you exit tmux without quitting the entire terminal! :|
            – Louis Maddox
            Aug 2 '15 at 20:43






          • 4




            @LouisMaddox: exec replaces the current process with a new one - in this case, it replaces the bash login shell with tmux, so when tmux exits then there is no other terminal to fall back to :)
            – Mark K Cowan
            Dec 8 '15 at 12:21










          • For those curious, it looks like command -v tests for the existence of tmux in the path.
            – Eric Hu
            Feb 19 '18 at 3:55



















          11














          Adding a line like



          [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session && exit;}


          in your bashrc file will probably do the job. Note this line will exit ssh and terminate the connection once you detach or exit tmux. I like this configuration as it saves key strokes to terminate the connection. But if you don't love this(which I think is very unlikely) and would rather remain in the login shell after termination, just remove the exit part:



          [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session;}


          Also note you shouldn't wrap tmux attach with exec, as this would cause the connection to be closed when there are no tmux sessions to attach to.






          share|improve this answer































            5














            There is command chsh which changes login shell. Consult man chsh.






            share|improve this answer

















            • 5




              tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm.
              – Mikel
              Jul 20 '12 at 15:32










            • Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo).
              – n.st
              May 11 '14 at 2:11






            • 2




              tmux as of at least 1.8 on Ubuntu adds itself to /etc/shells, so it is a valid login shell.
              – claytron
              Mar 26 '15 at 17:14






            • 2




              This requires you configure the default-shell setting in the tmux configuration to point to an actual shell.
              – Kusalananda
              Jan 14 '17 at 13:35





















            2














            I'm successfully using



            case $- in *i*)
            [ -z "$TMUX" ] && exec tmux
            esac


            in my .zshrc. If you're using bash, put it in your .bashrc instead.





            I also just tried setting tmux as my default shell (chsh -s $(which tmux)) and it seems to break direct command execution via SSH, e.g. ssh $some_server echo foo will not produce any output.






            share|improve this answer





























              1














              Add this into your ~/.tmux.conf



              set -g default-command /usr/local/bin/fish





              share|improve this answer





















              • I think you misunderstood the question mate! ;)
                – PhilT
                May 6 '17 at 5:29



















              1














              None of the above responses worked for me - exec tmux prevents me closing tmux without quitting the shell (whether it's opened with Ctrl + T or from the application menu).



              I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B does some sort of convoluted bash -exec(vim) statement to edit my .bashrc, so it acts like a regular shell.



              tmux loaded rather than vim under that situation after placing the above at the top of my .bashrc. I've wrapped the tmux executing line in another if statement, checking that it's running in interactive mode.



              if command -v tmux>/dev/null; then
              if [ ! -z "$PS1" ]; then # unless shell not loaded interactively, run tmux
              [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux
              fi
              fi


              You could wrap all that onto one line but for readability I think that's fine.






              share|improve this answer





















              • Adding a ampersand would solved that issue like so. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux &
                – Daniel Chateau
                Oct 6 '15 at 20:21





















              1














              Go to terminal preferances.
              enter image description here



              And then click to "command" bar.
              enter image description here



              Check the "Run a custom command instead of my sell" and write whatever command you want to execute at the startup of your terminal.






              share|improve this answer





























                1














                This is in my ~/.profile (I'm using ksh93):



                if [[ -z "$TMUX" ]]; then
                if tmux has-session 2>/dev/null; then
                exec tmux attach
                else
                exec tmux
                fi
                fi


                If the TMUX environment variable is unset/empty, then we're not already in a tmux session, so...



                If tmux has-session returns with a zero exit status (true), there is an available session to attach to. Attach to it.



                If not, create a new session.



                It's also possible to use tmux as your login shell. If you do this, however, make sure to set default-shell to an actual shell in your ~/.tmux.conf file (see the tmux manual for more info about this).






                share|improve this answer































                  1














                  You could (and as of now probably should) use chsh command to set tmux as default shell, then add the following to .tmux.conf:



                  set-option -g default-shell /path/to/your/favourite/shell


                  Just remember to modify the path at the end of the line.






                  share|improve this answer































                    0














                    Adding to @Louis Maddox 's answer, I would execute tmux part with;



                    (exec tmux attach || exec tmux new-session)





                    share|improve this answer























                    • I use exec sh -c 'tmux a || tmux', which (after looking at your answer) will probably make bad things happen if tmux can't start for any reason..... thanks, I'll use yours from now on :)
                      – Mark K Cowan
                      Dec 8 '15 at 12:22






                    • 1




                      tmux new -A -s mysession will probably work too.
                      – poolie
                      Apr 22 '16 at 1:16



















                    0














                    I combined the extensive checks, with the conditional session checking, and put my own spin on it, to create a default session that is connected to or else created. Unless you are inside of another tmux session, or other protective conditions are met.




                    if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                    tmux a -t default || exec tmux new -s default && exit;
                    fi



                    Based on these answers:



                    https://unix.stackexchange.com/a/306165/198110



                    https://unix.stackexchange.com/a/113768/198110






                    share|improve this answer





























                      -3














                      As Mikel already stated in his comment to have tmux as your login shell can have side effects. But you can make tmux your default shell, literally. A user's default shell is defined in /etc/passwd. So you can become root and edit /etc/passwd, e.g. sudo vi /etc/passwd search for the line that begins with your username. It probably ends with :/bin/bash. Change /bin/bash to /usr/bin/tmux and now tmux is your default login shell.



                      However, no guarantee that this won't cause problems!



                      What may work better is to NOT do anything that requries root privileges. I would try to create a file in my home directoy named .bash_login and start tmux from within that file: `echo "tmux" >~/.bash_login.



                      This should work, but you have to try and find our yourself, b/c the bash documentation is not very exact about what file is read and executed when.






                      share|improve this answer

















                      • 2




                        What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins.
                        – Gilles
                        Jul 20 '12 at 23:10











                      Your Answer








                      StackExchange.ready(function() {
                      var channelOptions = {
                      tags: "".split(" "),
                      id: "106"
                      };
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function() {
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled) {
                      StackExchange.using("snippets", function() {
                      createEditor();
                      });
                      }
                      else {
                      createEditor();
                      }
                      });

                      function createEditor() {
                      StackExchange.prepareEditor({
                      heartbeatType: 'answer',
                      autoActivateHeartbeat: false,
                      convertImagesToLinks: false,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: null,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader: {
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      },
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      });


                      }
                      });














                      draft saved

                      draft discarded


















                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f43601%2fhow-can-i-set-my-default-shell-to-start-up-tmux%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown

























                      13 Answers
                      13






                      active

                      oldest

                      votes








                      13 Answers
                      13






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      40














                      This seems to work...



                      https://wiki.archlinux.org/index.php/Tmux#Start_tmux_on_every_shell_login



                      Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar:



                      [[ $TERM != "screen" ]] && exec tmux





                      share|improve this answer



















                      • 2




                        For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page)
                        – Keith Smiley
                        Apr 14 '13 at 1:45






                      • 2




                        This is a bad solution since the TERM might be set to some other value by the user's .tmux.conf file. Better to check whether the TMUX variable is set or not.
                        – Kusalananda
                        Dec 30 '16 at 13:21
















                      40














                      This seems to work...



                      https://wiki.archlinux.org/index.php/Tmux#Start_tmux_on_every_shell_login



                      Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar:



                      [[ $TERM != "screen" ]] && exec tmux





                      share|improve this answer



















                      • 2




                        For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page)
                        – Keith Smiley
                        Apr 14 '13 at 1:45






                      • 2




                        This is a bad solution since the TERM might be set to some other value by the user's .tmux.conf file. Better to check whether the TMUX variable is set or not.
                        – Kusalananda
                        Dec 30 '16 at 13:21














                      40












                      40








                      40






                      This seems to work...



                      https://wiki.archlinux.org/index.php/Tmux#Start_tmux_on_every_shell_login



                      Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar:



                      [[ $TERM != "screen" ]] && exec tmux





                      share|improve this answer














                      This seems to work...



                      https://wiki.archlinux.org/index.php/Tmux#Start_tmux_on_every_shell_login



                      Simply add the following line of bash code to your .bashrc before your aliases; the code for other shells is very similar:



                      [[ $TERM != "screen" ]] && exec tmux






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Jul 21 '12 at 0:12

























                      answered Jul 20 '12 at 15:08









                      StarNamer

                      2,09511324




                      2,09511324








                      • 2




                        For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page)
                        – Keith Smiley
                        Apr 14 '13 at 1:45






                      • 2




                        This is a bad solution since the TERM might be set to some other value by the user's .tmux.conf file. Better to check whether the TMUX variable is set or not.
                        – Kusalananda
                        Dec 30 '16 at 13:21














                      • 2




                        For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page)
                        – Keith Smiley
                        Apr 14 '13 at 1:45






                      • 2




                        This is a bad solution since the TERM might be set to some other value by the user's .tmux.conf file. Better to check whether the TMUX variable is set or not.
                        – Kusalananda
                        Dec 30 '16 at 13:21








                      2




                      2




                      For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page)
                      – Keith Smiley
                      Apr 14 '13 at 1:45




                      For me this also required [[ $- != *i* ]] && return to not being an infinite loop (from the same page)
                      – Keith Smiley
                      Apr 14 '13 at 1:45




                      2




                      2




                      This is a bad solution since the TERM might be set to some other value by the user's .tmux.conf file. Better to check whether the TMUX variable is set or not.
                      – Kusalananda
                      Dec 30 '16 at 13:21




                      This is a bad solution since the TERM might be set to some other value by the user's .tmux.conf file. Better to check whether the TMUX variable is set or not.
                      – Kusalananda
                      Dec 30 '16 at 13:21













                      79














                      @StarNamer's answer is generally accurate, though I typically include the following tests to make sure that (1) tmux exists on the system, (2) we're in an interactive shell, and (3) tmux doesn't try to run within itself:



                      if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                      exec tmux
                      fi




                      References




                      • Using bash's command to check for existence of a command - http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_BUILTIN_COMMANDS

                      • Why to use command instead of which to check for the existence of commands - https://unix.stackexchange.com/a/85250

                      • Using $PS1 to check for interactive shell - https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html

                      • Expected state of $TERM environment variable "for all programs running inside tmux" - http://man7.org/linux/man-pages/man1/tmux.1.html#WINDOWS_AND_PANES






                      share|improve this answer



















                      • 1




                        Nice, I have needed command before but didn't realize it existed.
                        – Freedom_Ben
                        Jun 21 '15 at 0:25










                      • I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B edits my .bashrc. Vim can't open for some reason if the above is at the top of the bashrc. I've wrapped the middle line in another if statement, if [ ! -z "$PS1" ]; then...fi (checking that it's running in interactive mode)
                        – Louis Maddox
                        Aug 2 '15 at 20:03








                      • 2




                        this exec statement doesn't let you exit tmux without quitting the entire terminal! :|
                        – Louis Maddox
                        Aug 2 '15 at 20:43






                      • 4




                        @LouisMaddox: exec replaces the current process with a new one - in this case, it replaces the bash login shell with tmux, so when tmux exits then there is no other terminal to fall back to :)
                        – Mark K Cowan
                        Dec 8 '15 at 12:21










                      • For those curious, it looks like command -v tests for the existence of tmux in the path.
                        – Eric Hu
                        Feb 19 '18 at 3:55
















                      79














                      @StarNamer's answer is generally accurate, though I typically include the following tests to make sure that (1) tmux exists on the system, (2) we're in an interactive shell, and (3) tmux doesn't try to run within itself:



                      if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                      exec tmux
                      fi




                      References




                      • Using bash's command to check for existence of a command - http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_BUILTIN_COMMANDS

                      • Why to use command instead of which to check for the existence of commands - https://unix.stackexchange.com/a/85250

                      • Using $PS1 to check for interactive shell - https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html

                      • Expected state of $TERM environment variable "for all programs running inside tmux" - http://man7.org/linux/man-pages/man1/tmux.1.html#WINDOWS_AND_PANES






                      share|improve this answer



















                      • 1




                        Nice, I have needed command before but didn't realize it existed.
                        – Freedom_Ben
                        Jun 21 '15 at 0:25










                      • I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B edits my .bashrc. Vim can't open for some reason if the above is at the top of the bashrc. I've wrapped the middle line in another if statement, if [ ! -z "$PS1" ]; then...fi (checking that it's running in interactive mode)
                        – Louis Maddox
                        Aug 2 '15 at 20:03








                      • 2




                        this exec statement doesn't let you exit tmux without quitting the entire terminal! :|
                        – Louis Maddox
                        Aug 2 '15 at 20:43






                      • 4




                        @LouisMaddox: exec replaces the current process with a new one - in this case, it replaces the bash login shell with tmux, so when tmux exits then there is no other terminal to fall back to :)
                        – Mark K Cowan
                        Dec 8 '15 at 12:21










                      • For those curious, it looks like command -v tests for the existence of tmux in the path.
                        – Eric Hu
                        Feb 19 '18 at 3:55














                      79












                      79








                      79






                      @StarNamer's answer is generally accurate, though I typically include the following tests to make sure that (1) tmux exists on the system, (2) we're in an interactive shell, and (3) tmux doesn't try to run within itself:



                      if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                      exec tmux
                      fi




                      References




                      • Using bash's command to check for existence of a command - http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_BUILTIN_COMMANDS

                      • Why to use command instead of which to check for the existence of commands - https://unix.stackexchange.com/a/85250

                      • Using $PS1 to check for interactive shell - https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html

                      • Expected state of $TERM environment variable "for all programs running inside tmux" - http://man7.org/linux/man-pages/man1/tmux.1.html#WINDOWS_AND_PANES






                      share|improve this answer














                      @StarNamer's answer is generally accurate, though I typically include the following tests to make sure that (1) tmux exists on the system, (2) we're in an interactive shell, and (3) tmux doesn't try to run within itself:



                      if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                      exec tmux
                      fi




                      References




                      • Using bash's command to check for existence of a command - http://man7.org/linux/man-pages/man1/bash.1.html#SHELL_BUILTIN_COMMANDS

                      • Why to use command instead of which to check for the existence of commands - https://unix.stackexchange.com/a/85250

                      • Using $PS1 to check for interactive shell - https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html

                      • Expected state of $TERM environment variable "for all programs running inside tmux" - http://man7.org/linux/man-pages/man1/tmux.1.html#WINDOWS_AND_PANES







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Oct 3 '18 at 5:38

























                      answered Feb 6 '14 at 0:38









                      user7089

                      1,1492911




                      1,1492911








                      • 1




                        Nice, I have needed command before but didn't realize it existed.
                        – Freedom_Ben
                        Jun 21 '15 at 0:25










                      • I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B edits my .bashrc. Vim can't open for some reason if the above is at the top of the bashrc. I've wrapped the middle line in another if statement, if [ ! -z "$PS1" ]; then...fi (checking that it's running in interactive mode)
                        – Louis Maddox
                        Aug 2 '15 at 20:03








                      • 2




                        this exec statement doesn't let you exit tmux without quitting the entire terminal! :|
                        – Louis Maddox
                        Aug 2 '15 at 20:43






                      • 4




                        @LouisMaddox: exec replaces the current process with a new one - in this case, it replaces the bash login shell with tmux, so when tmux exits then there is no other terminal to fall back to :)
                        – Mark K Cowan
                        Dec 8 '15 at 12:21










                      • For those curious, it looks like command -v tests for the existence of tmux in the path.
                        – Eric Hu
                        Feb 19 '18 at 3:55














                      • 1




                        Nice, I have needed command before but didn't realize it existed.
                        – Freedom_Ben
                        Jun 21 '15 at 0:25










                      • I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B edits my .bashrc. Vim can't open for some reason if the above is at the top of the bashrc. I've wrapped the middle line in another if statement, if [ ! -z "$PS1" ]; then...fi (checking that it's running in interactive mode)
                        – Louis Maddox
                        Aug 2 '15 at 20:03








                      • 2




                        this exec statement doesn't let you exit tmux without quitting the entire terminal! :|
                        – Louis Maddox
                        Aug 2 '15 at 20:43






                      • 4




                        @LouisMaddox: exec replaces the current process with a new one - in this case, it replaces the bash login shell with tmux, so when tmux exits then there is no other terminal to fall back to :)
                        – Mark K Cowan
                        Dec 8 '15 at 12:21










                      • For those curious, it looks like command -v tests for the existence of tmux in the path.
                        – Eric Hu
                        Feb 19 '18 at 3:55








                      1




                      1




                      Nice, I have needed command before but didn't realize it existed.
                      – Freedom_Ben
                      Jun 21 '15 at 0:25




                      Nice, I have needed command before but didn't realize it existed.
                      – Freedom_Ben
                      Jun 21 '15 at 0:25












                      I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B edits my .bashrc. Vim can't open for some reason if the above is at the top of the bashrc. I've wrapped the middle line in another if statement, if [ ! -z "$PS1" ]; then...fi (checking that it's running in interactive mode)
                      – Louis Maddox
                      Aug 2 '15 at 20:03






                      I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B edits my .bashrc. Vim can't open for some reason if the above is at the top of the bashrc. I've wrapped the middle line in another if statement, if [ ! -z "$PS1" ]; then...fi (checking that it's running in interactive mode)
                      – Louis Maddox
                      Aug 2 '15 at 20:03






                      2




                      2




                      this exec statement doesn't let you exit tmux without quitting the entire terminal! :|
                      – Louis Maddox
                      Aug 2 '15 at 20:43




                      this exec statement doesn't let you exit tmux without quitting the entire terminal! :|
                      – Louis Maddox
                      Aug 2 '15 at 20:43




                      4




                      4




                      @LouisMaddox: exec replaces the current process with a new one - in this case, it replaces the bash login shell with tmux, so when tmux exits then there is no other terminal to fall back to :)
                      – Mark K Cowan
                      Dec 8 '15 at 12:21




                      @LouisMaddox: exec replaces the current process with a new one - in this case, it replaces the bash login shell with tmux, so when tmux exits then there is no other terminal to fall back to :)
                      – Mark K Cowan
                      Dec 8 '15 at 12:21












                      For those curious, it looks like command -v tests for the existence of tmux in the path.
                      – Eric Hu
                      Feb 19 '18 at 3:55




                      For those curious, it looks like command -v tests for the existence of tmux in the path.
                      – Eric Hu
                      Feb 19 '18 at 3:55











                      11














                      Adding a line like



                      [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session && exit;}


                      in your bashrc file will probably do the job. Note this line will exit ssh and terminate the connection once you detach or exit tmux. I like this configuration as it saves key strokes to terminate the connection. But if you don't love this(which I think is very unlikely) and would rather remain in the login shell after termination, just remove the exit part:



                      [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session;}


                      Also note you shouldn't wrap tmux attach with exec, as this would cause the connection to be closed when there are no tmux sessions to attach to.






                      share|improve this answer




























                        11














                        Adding a line like



                        [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session && exit;}


                        in your bashrc file will probably do the job. Note this line will exit ssh and terminate the connection once you detach or exit tmux. I like this configuration as it saves key strokes to terminate the connection. But if you don't love this(which I think is very unlikely) and would rather remain in the login shell after termination, just remove the exit part:



                        [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session;}


                        Also note you shouldn't wrap tmux attach with exec, as this would cause the connection to be closed when there are no tmux sessions to attach to.






                        share|improve this answer


























                          11












                          11








                          11






                          Adding a line like



                          [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session && exit;}


                          in your bashrc file will probably do the job. Note this line will exit ssh and terminate the connection once you detach or exit tmux. I like this configuration as it saves key strokes to terminate the connection. But if you don't love this(which I think is very unlikely) and would rather remain in the login shell after termination, just remove the exit part:



                          [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session;}


                          Also note you shouldn't wrap tmux attach with exec, as this would cause the connection to be closed when there are no tmux sessions to attach to.






                          share|improve this answer














                          Adding a line like



                          [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session && exit;}


                          in your bashrc file will probably do the job. Note this line will exit ssh and terminate the connection once you detach or exit tmux. I like this configuration as it saves key strokes to terminate the connection. But if you don't love this(which I think is very unlikely) and would rather remain in the login shell after termination, just remove the exit part:



                          [ -z "$TMUX"  ] && { tmux attach || exec tmux new-session;}


                          Also note you shouldn't wrap tmux attach with exec, as this would cause the connection to be closed when there are no tmux sessions to attach to.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 18 '18 at 18:36

























                          answered Aug 28 '16 at 5:03









                          huangzonghao

                          11615




                          11615























                              5














                              There is command chsh which changes login shell. Consult man chsh.






                              share|improve this answer

















                              • 5




                                tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm.
                                – Mikel
                                Jul 20 '12 at 15:32










                              • Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo).
                                – n.st
                                May 11 '14 at 2:11






                              • 2




                                tmux as of at least 1.8 on Ubuntu adds itself to /etc/shells, so it is a valid login shell.
                                – claytron
                                Mar 26 '15 at 17:14






                              • 2




                                This requires you configure the default-shell setting in the tmux configuration to point to an actual shell.
                                – Kusalananda
                                Jan 14 '17 at 13:35


















                              5














                              There is command chsh which changes login shell. Consult man chsh.






                              share|improve this answer

















                              • 5




                                tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm.
                                – Mikel
                                Jul 20 '12 at 15:32










                              • Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo).
                                – n.st
                                May 11 '14 at 2:11






                              • 2




                                tmux as of at least 1.8 on Ubuntu adds itself to /etc/shells, so it is a valid login shell.
                                – claytron
                                Mar 26 '15 at 17:14






                              • 2




                                This requires you configure the default-shell setting in the tmux configuration to point to an actual shell.
                                – Kusalananda
                                Jan 14 '17 at 13:35
















                              5












                              5








                              5






                              There is command chsh which changes login shell. Consult man chsh.






                              share|improve this answer












                              There is command chsh which changes login shell. Consult man chsh.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jul 20 '12 at 14:42









                              paul

                              1,127167




                              1,127167








                              • 5




                                tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm.
                                – Mikel
                                Jul 20 '12 at 15:32










                              • Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo).
                                – n.st
                                May 11 '14 at 2:11






                              • 2




                                tmux as of at least 1.8 on Ubuntu adds itself to /etc/shells, so it is a valid login shell.
                                – claytron
                                Mar 26 '15 at 17:14






                              • 2




                                This requires you configure the default-shell setting in the tmux configuration to point to an actual shell.
                                – Kusalananda
                                Jan 14 '17 at 13:35
















                              • 5




                                tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm.
                                – Mikel
                                Jul 20 '12 at 15:32










                              • Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo).
                                – n.st
                                May 11 '14 at 2:11






                              • 2




                                tmux as of at least 1.8 on Ubuntu adds itself to /etc/shells, so it is a valid login shell.
                                – claytron
                                Mar 26 '15 at 17:14






                              • 2




                                This requires you configure the default-shell setting in the tmux configuration to point to an actual shell.
                                – Kusalananda
                                Jan 14 '17 at 13:35










                              5




                              5




                              tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm.
                              – Mikel
                              Jul 20 '12 at 15:32




                              tmux is not a shell, it's a terminal multiplexer like GNU screen. Interestingly, it does support the -c option according to the man page, so it may work like a shell just enough to use it as your login shell, but I suspect it won't work properly in all situations, e.g. graphical logins via gdm/kdm.
                              – Mikel
                              Jul 20 '12 at 15:32












                              Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo).
                              – n.st
                              May 11 '14 at 2:11




                              Although this is sensible and backed by the documentation, it seems to break direct command execution via SSH (something like ssh $some_server echo foo).
                              – n.st
                              May 11 '14 at 2:11




                              2




                              2




                              tmux as of at least 1.8 on Ubuntu adds itself to /etc/shells, so it is a valid login shell.
                              – claytron
                              Mar 26 '15 at 17:14




                              tmux as of at least 1.8 on Ubuntu adds itself to /etc/shells, so it is a valid login shell.
                              – claytron
                              Mar 26 '15 at 17:14




                              2




                              2




                              This requires you configure the default-shell setting in the tmux configuration to point to an actual shell.
                              – Kusalananda
                              Jan 14 '17 at 13:35






                              This requires you configure the default-shell setting in the tmux configuration to point to an actual shell.
                              – Kusalananda
                              Jan 14 '17 at 13:35













                              2














                              I'm successfully using



                              case $- in *i*)
                              [ -z "$TMUX" ] && exec tmux
                              esac


                              in my .zshrc. If you're using bash, put it in your .bashrc instead.





                              I also just tried setting tmux as my default shell (chsh -s $(which tmux)) and it seems to break direct command execution via SSH, e.g. ssh $some_server echo foo will not produce any output.






                              share|improve this answer


























                                2














                                I'm successfully using



                                case $- in *i*)
                                [ -z "$TMUX" ] && exec tmux
                                esac


                                in my .zshrc. If you're using bash, put it in your .bashrc instead.





                                I also just tried setting tmux as my default shell (chsh -s $(which tmux)) and it seems to break direct command execution via SSH, e.g. ssh $some_server echo foo will not produce any output.






                                share|improve this answer
























                                  2












                                  2








                                  2






                                  I'm successfully using



                                  case $- in *i*)
                                  [ -z "$TMUX" ] && exec tmux
                                  esac


                                  in my .zshrc. If you're using bash, put it in your .bashrc instead.





                                  I also just tried setting tmux as my default shell (chsh -s $(which tmux)) and it seems to break direct command execution via SSH, e.g. ssh $some_server echo foo will not produce any output.






                                  share|improve this answer












                                  I'm successfully using



                                  case $- in *i*)
                                  [ -z "$TMUX" ] && exec tmux
                                  esac


                                  in my .zshrc. If you're using bash, put it in your .bashrc instead.





                                  I also just tried setting tmux as my default shell (chsh -s $(which tmux)) and it seems to break direct command execution via SSH, e.g. ssh $some_server echo foo will not produce any output.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered May 11 '14 at 2:09









                                  n.st

                                  5,25611943




                                  5,25611943























                                      1














                                      Add this into your ~/.tmux.conf



                                      set -g default-command /usr/local/bin/fish





                                      share|improve this answer





















                                      • I think you misunderstood the question mate! ;)
                                        – PhilT
                                        May 6 '17 at 5:29
















                                      1














                                      Add this into your ~/.tmux.conf



                                      set -g default-command /usr/local/bin/fish





                                      share|improve this answer





















                                      • I think you misunderstood the question mate! ;)
                                        – PhilT
                                        May 6 '17 at 5:29














                                      1












                                      1








                                      1






                                      Add this into your ~/.tmux.conf



                                      set -g default-command /usr/local/bin/fish





                                      share|improve this answer












                                      Add this into your ~/.tmux.conf



                                      set -g default-command /usr/local/bin/fish






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jun 19 '14 at 16:49









                                      IanVaughan

                                      1466




                                      1466












                                      • I think you misunderstood the question mate! ;)
                                        – PhilT
                                        May 6 '17 at 5:29


















                                      • I think you misunderstood the question mate! ;)
                                        – PhilT
                                        May 6 '17 at 5:29
















                                      I think you misunderstood the question mate! ;)
                                      – PhilT
                                      May 6 '17 at 5:29




                                      I think you misunderstood the question mate! ;)
                                      – PhilT
                                      May 6 '17 at 5:29











                                      1














                                      None of the above responses worked for me - exec tmux prevents me closing tmux without quitting the shell (whether it's opened with Ctrl + T or from the application menu).



                                      I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B does some sort of convoluted bash -exec(vim) statement to edit my .bashrc, so it acts like a regular shell.



                                      tmux loaded rather than vim under that situation after placing the above at the top of my .bashrc. I've wrapped the tmux executing line in another if statement, checking that it's running in interactive mode.



                                      if command -v tmux>/dev/null; then
                                      if [ ! -z "$PS1" ]; then # unless shell not loaded interactively, run tmux
                                      [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux
                                      fi
                                      fi


                                      You could wrap all that onto one line but for readability I think that's fine.






                                      share|improve this answer





















                                      • Adding a ampersand would solved that issue like so. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux &
                                        – Daniel Chateau
                                        Oct 6 '15 at 20:21


















                                      1














                                      None of the above responses worked for me - exec tmux prevents me closing tmux without quitting the shell (whether it's opened with Ctrl + T or from the application menu).



                                      I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B does some sort of convoluted bash -exec(vim) statement to edit my .bashrc, so it acts like a regular shell.



                                      tmux loaded rather than vim under that situation after placing the above at the top of my .bashrc. I've wrapped the tmux executing line in another if statement, checking that it's running in interactive mode.



                                      if command -v tmux>/dev/null; then
                                      if [ ! -z "$PS1" ]; then # unless shell not loaded interactively, run tmux
                                      [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux
                                      fi
                                      fi


                                      You could wrap all that onto one line but for readability I think that's fine.






                                      share|improve this answer





















                                      • Adding a ampersand would solved that issue like so. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux &
                                        – Daniel Chateau
                                        Oct 6 '15 at 20:21
















                                      1












                                      1








                                      1






                                      None of the above responses worked for me - exec tmux prevents me closing tmux without quitting the shell (whether it's opened with Ctrl + T or from the application menu).



                                      I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B does some sort of convoluted bash -exec(vim) statement to edit my .bashrc, so it acts like a regular shell.



                                      tmux loaded rather than vim under that situation after placing the above at the top of my .bashrc. I've wrapped the tmux executing line in another if statement, checking that it's running in interactive mode.



                                      if command -v tmux>/dev/null; then
                                      if [ ! -z "$PS1" ]; then # unless shell not loaded interactively, run tmux
                                      [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux
                                      fi
                                      fi


                                      You could wrap all that onto one line but for readability I think that's fine.






                                      share|improve this answer












                                      None of the above responses worked for me - exec tmux prevents me closing tmux without quitting the shell (whether it's opened with Ctrl + T or from the application menu).



                                      I use Linux Mint, which lets you map certain hotkeys to commands, and (un-kosher as it may be to some..) I've got bash shells with commands starting up there, e.g. Win+Alt+B does some sort of convoluted bash -exec(vim) statement to edit my .bashrc, so it acts like a regular shell.



                                      tmux loaded rather than vim under that situation after placing the above at the top of my .bashrc. I've wrapped the tmux executing line in another if statement, checking that it's running in interactive mode.



                                      if command -v tmux>/dev/null; then
                                      if [ ! -z "$PS1" ]; then # unless shell not loaded interactively, run tmux
                                      [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux
                                      fi
                                      fi


                                      You could wrap all that onto one line but for readability I think that's fine.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 2 '15 at 21:54









                                      Louis Maddox

                                      1636




                                      1636












                                      • Adding a ampersand would solved that issue like so. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux &
                                        – Daniel Chateau
                                        Oct 6 '15 at 20:21




















                                      • Adding a ampersand would solved that issue like so. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux &
                                        – Daniel Chateau
                                        Oct 6 '15 at 20:21


















                                      Adding a ampersand would solved that issue like so. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux &
                                      – Daniel Chateau
                                      Oct 6 '15 at 20:21






                                      Adding a ampersand would solved that issue like so. [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux &
                                      – Daniel Chateau
                                      Oct 6 '15 at 20:21













                                      1














                                      Go to terminal preferances.
                                      enter image description here



                                      And then click to "command" bar.
                                      enter image description here



                                      Check the "Run a custom command instead of my sell" and write whatever command you want to execute at the startup of your terminal.






                                      share|improve this answer


























                                        1














                                        Go to terminal preferances.
                                        enter image description here



                                        And then click to "command" bar.
                                        enter image description here



                                        Check the "Run a custom command instead of my sell" and write whatever command you want to execute at the startup of your terminal.






                                        share|improve this answer
























                                          1












                                          1








                                          1






                                          Go to terminal preferances.
                                          enter image description here



                                          And then click to "command" bar.
                                          enter image description here



                                          Check the "Run a custom command instead of my sell" and write whatever command you want to execute at the startup of your terminal.






                                          share|improve this answer












                                          Go to terminal preferances.
                                          enter image description here



                                          And then click to "command" bar.
                                          enter image description here



                                          Check the "Run a custom command instead of my sell" and write whatever command you want to execute at the startup of your terminal.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Jun 13 '16 at 21:09









                                          user174935

                                          111




                                          111























                                              1














                                              This is in my ~/.profile (I'm using ksh93):



                                              if [[ -z "$TMUX" ]]; then
                                              if tmux has-session 2>/dev/null; then
                                              exec tmux attach
                                              else
                                              exec tmux
                                              fi
                                              fi


                                              If the TMUX environment variable is unset/empty, then we're not already in a tmux session, so...



                                              If tmux has-session returns with a zero exit status (true), there is an available session to attach to. Attach to it.



                                              If not, create a new session.



                                              It's also possible to use tmux as your login shell. If you do this, however, make sure to set default-shell to an actual shell in your ~/.tmux.conf file (see the tmux manual for more info about this).






                                              share|improve this answer




























                                                1














                                                This is in my ~/.profile (I'm using ksh93):



                                                if [[ -z "$TMUX" ]]; then
                                                if tmux has-session 2>/dev/null; then
                                                exec tmux attach
                                                else
                                                exec tmux
                                                fi
                                                fi


                                                If the TMUX environment variable is unset/empty, then we're not already in a tmux session, so...



                                                If tmux has-session returns with a zero exit status (true), there is an available session to attach to. Attach to it.



                                                If not, create a new session.



                                                It's also possible to use tmux as your login shell. If you do this, however, make sure to set default-shell to an actual shell in your ~/.tmux.conf file (see the tmux manual for more info about this).






                                                share|improve this answer


























                                                  1












                                                  1








                                                  1






                                                  This is in my ~/.profile (I'm using ksh93):



                                                  if [[ -z "$TMUX" ]]; then
                                                  if tmux has-session 2>/dev/null; then
                                                  exec tmux attach
                                                  else
                                                  exec tmux
                                                  fi
                                                  fi


                                                  If the TMUX environment variable is unset/empty, then we're not already in a tmux session, so...



                                                  If tmux has-session returns with a zero exit status (true), there is an available session to attach to. Attach to it.



                                                  If not, create a new session.



                                                  It's also possible to use tmux as your login shell. If you do this, however, make sure to set default-shell to an actual shell in your ~/.tmux.conf file (see the tmux manual for more info about this).






                                                  share|improve this answer














                                                  This is in my ~/.profile (I'm using ksh93):



                                                  if [[ -z "$TMUX" ]]; then
                                                  if tmux has-session 2>/dev/null; then
                                                  exec tmux attach
                                                  else
                                                  exec tmux
                                                  fi
                                                  fi


                                                  If the TMUX environment variable is unset/empty, then we're not already in a tmux session, so...



                                                  If tmux has-session returns with a zero exit status (true), there is an available session to attach to. Attach to it.



                                                  If not, create a new session.



                                                  It's also possible to use tmux as your login shell. If you do this, however, make sure to set default-shell to an actual shell in your ~/.tmux.conf file (see the tmux manual for more info about this).







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Dec 30 '16 at 13:51

























                                                  answered Dec 30 '16 at 13:26









                                                  Kusalananda

                                                  122k16230375




                                                  122k16230375























                                                      1














                                                      You could (and as of now probably should) use chsh command to set tmux as default shell, then add the following to .tmux.conf:



                                                      set-option -g default-shell /path/to/your/favourite/shell


                                                      Just remember to modify the path at the end of the line.






                                                      share|improve this answer




























                                                        1














                                                        You could (and as of now probably should) use chsh command to set tmux as default shell, then add the following to .tmux.conf:



                                                        set-option -g default-shell /path/to/your/favourite/shell


                                                        Just remember to modify the path at the end of the line.






                                                        share|improve this answer


























                                                          1












                                                          1








                                                          1






                                                          You could (and as of now probably should) use chsh command to set tmux as default shell, then add the following to .tmux.conf:



                                                          set-option -g default-shell /path/to/your/favourite/shell


                                                          Just remember to modify the path at the end of the line.






                                                          share|improve this answer














                                                          You could (and as of now probably should) use chsh command to set tmux as default shell, then add the following to .tmux.conf:



                                                          set-option -g default-shell /path/to/your/favourite/shell


                                                          Just remember to modify the path at the end of the line.







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Jan 14 '17 at 13:17

























                                                          answered Dec 30 '16 at 12:51









                                                          Błażej Michalik

                                                          1537




                                                          1537























                                                              0














                                                              Adding to @Louis Maddox 's answer, I would execute tmux part with;



                                                              (exec tmux attach || exec tmux new-session)





                                                              share|improve this answer























                                                              • I use exec sh -c 'tmux a || tmux', which (after looking at your answer) will probably make bad things happen if tmux can't start for any reason..... thanks, I'll use yours from now on :)
                                                                – Mark K Cowan
                                                                Dec 8 '15 at 12:22






                                                              • 1




                                                                tmux new -A -s mysession will probably work too.
                                                                – poolie
                                                                Apr 22 '16 at 1:16
















                                                              0














                                                              Adding to @Louis Maddox 's answer, I would execute tmux part with;



                                                              (exec tmux attach || exec tmux new-session)





                                                              share|improve this answer























                                                              • I use exec sh -c 'tmux a || tmux', which (after looking at your answer) will probably make bad things happen if tmux can't start for any reason..... thanks, I'll use yours from now on :)
                                                                – Mark K Cowan
                                                                Dec 8 '15 at 12:22






                                                              • 1




                                                                tmux new -A -s mysession will probably work too.
                                                                – poolie
                                                                Apr 22 '16 at 1:16














                                                              0












                                                              0








                                                              0






                                                              Adding to @Louis Maddox 's answer, I would execute tmux part with;



                                                              (exec tmux attach || exec tmux new-session)





                                                              share|improve this answer














                                                              Adding to @Louis Maddox 's answer, I would execute tmux part with;



                                                              (exec tmux attach || exec tmux new-session)






                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Nov 11 '15 at 22:49

























                                                              answered Nov 11 '15 at 22:38









                                                              devrimbaris

                                                              1013




                                                              1013












                                                              • I use exec sh -c 'tmux a || tmux', which (after looking at your answer) will probably make bad things happen if tmux can't start for any reason..... thanks, I'll use yours from now on :)
                                                                – Mark K Cowan
                                                                Dec 8 '15 at 12:22






                                                              • 1




                                                                tmux new -A -s mysession will probably work too.
                                                                – poolie
                                                                Apr 22 '16 at 1:16


















                                                              • I use exec sh -c 'tmux a || tmux', which (after looking at your answer) will probably make bad things happen if tmux can't start for any reason..... thanks, I'll use yours from now on :)
                                                                – Mark K Cowan
                                                                Dec 8 '15 at 12:22






                                                              • 1




                                                                tmux new -A -s mysession will probably work too.
                                                                – poolie
                                                                Apr 22 '16 at 1:16
















                                                              I use exec sh -c 'tmux a || tmux', which (after looking at your answer) will probably make bad things happen if tmux can't start for any reason..... thanks, I'll use yours from now on :)
                                                              – Mark K Cowan
                                                              Dec 8 '15 at 12:22




                                                              I use exec sh -c 'tmux a || tmux', which (after looking at your answer) will probably make bad things happen if tmux can't start for any reason..... thanks, I'll use yours from now on :)
                                                              – Mark K Cowan
                                                              Dec 8 '15 at 12:22




                                                              1




                                                              1




                                                              tmux new -A -s mysession will probably work too.
                                                              – poolie
                                                              Apr 22 '16 at 1:16




                                                              tmux new -A -s mysession will probably work too.
                                                              – poolie
                                                              Apr 22 '16 at 1:16











                                                              0














                                                              I combined the extensive checks, with the conditional session checking, and put my own spin on it, to create a default session that is connected to or else created. Unless you are inside of another tmux session, or other protective conditions are met.




                                                              if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                                                              tmux a -t default || exec tmux new -s default && exit;
                                                              fi



                                                              Based on these answers:



                                                              https://unix.stackexchange.com/a/306165/198110



                                                              https://unix.stackexchange.com/a/113768/198110






                                                              share|improve this answer


























                                                                0














                                                                I combined the extensive checks, with the conditional session checking, and put my own spin on it, to create a default session that is connected to or else created. Unless you are inside of another tmux session, or other protective conditions are met.




                                                                if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                                                                tmux a -t default || exec tmux new -s default && exit;
                                                                fi



                                                                Based on these answers:



                                                                https://unix.stackexchange.com/a/306165/198110



                                                                https://unix.stackexchange.com/a/113768/198110






                                                                share|improve this answer
























                                                                  0












                                                                  0








                                                                  0






                                                                  I combined the extensive checks, with the conditional session checking, and put my own spin on it, to create a default session that is connected to or else created. Unless you are inside of another tmux session, or other protective conditions are met.




                                                                  if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                                                                  tmux a -t default || exec tmux new -s default && exit;
                                                                  fi



                                                                  Based on these answers:



                                                                  https://unix.stackexchange.com/a/306165/198110



                                                                  https://unix.stackexchange.com/a/113768/198110






                                                                  share|improve this answer












                                                                  I combined the extensive checks, with the conditional session checking, and put my own spin on it, to create a default session that is connected to or else created. Unless you are inside of another tmux session, or other protective conditions are met.




                                                                  if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
                                                                  tmux a -t default || exec tmux new -s default && exit;
                                                                  fi



                                                                  Based on these answers:



                                                                  https://unix.stackexchange.com/a/306165/198110



                                                                  https://unix.stackexchange.com/a/113768/198110







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Dec 25 '18 at 0:45









                                                                  yosefrow

                                                                  17610




                                                                  17610























                                                                      -3














                                                                      As Mikel already stated in his comment to have tmux as your login shell can have side effects. But you can make tmux your default shell, literally. A user's default shell is defined in /etc/passwd. So you can become root and edit /etc/passwd, e.g. sudo vi /etc/passwd search for the line that begins with your username. It probably ends with :/bin/bash. Change /bin/bash to /usr/bin/tmux and now tmux is your default login shell.



                                                                      However, no guarantee that this won't cause problems!



                                                                      What may work better is to NOT do anything that requries root privileges. I would try to create a file in my home directoy named .bash_login and start tmux from within that file: `echo "tmux" >~/.bash_login.



                                                                      This should work, but you have to try and find our yourself, b/c the bash documentation is not very exact about what file is read and executed when.






                                                                      share|improve this answer

















                                                                      • 2




                                                                        What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins.
                                                                        – Gilles
                                                                        Jul 20 '12 at 23:10
















                                                                      -3














                                                                      As Mikel already stated in his comment to have tmux as your login shell can have side effects. But you can make tmux your default shell, literally. A user's default shell is defined in /etc/passwd. So you can become root and edit /etc/passwd, e.g. sudo vi /etc/passwd search for the line that begins with your username. It probably ends with :/bin/bash. Change /bin/bash to /usr/bin/tmux and now tmux is your default login shell.



                                                                      However, no guarantee that this won't cause problems!



                                                                      What may work better is to NOT do anything that requries root privileges. I would try to create a file in my home directoy named .bash_login and start tmux from within that file: `echo "tmux" >~/.bash_login.



                                                                      This should work, but you have to try and find our yourself, b/c the bash documentation is not very exact about what file is read and executed when.






                                                                      share|improve this answer

















                                                                      • 2




                                                                        What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins.
                                                                        – Gilles
                                                                        Jul 20 '12 at 23:10














                                                                      -3












                                                                      -3








                                                                      -3






                                                                      As Mikel already stated in his comment to have tmux as your login shell can have side effects. But you can make tmux your default shell, literally. A user's default shell is defined in /etc/passwd. So you can become root and edit /etc/passwd, e.g. sudo vi /etc/passwd search for the line that begins with your username. It probably ends with :/bin/bash. Change /bin/bash to /usr/bin/tmux and now tmux is your default login shell.



                                                                      However, no guarantee that this won't cause problems!



                                                                      What may work better is to NOT do anything that requries root privileges. I would try to create a file in my home directoy named .bash_login and start tmux from within that file: `echo "tmux" >~/.bash_login.



                                                                      This should work, but you have to try and find our yourself, b/c the bash documentation is not very exact about what file is read and executed when.






                                                                      share|improve this answer












                                                                      As Mikel already stated in his comment to have tmux as your login shell can have side effects. But you can make tmux your default shell, literally. A user's default shell is defined in /etc/passwd. So you can become root and edit /etc/passwd, e.g. sudo vi /etc/passwd search for the line that begins with your username. It probably ends with :/bin/bash. Change /bin/bash to /usr/bin/tmux and now tmux is your default login shell.



                                                                      However, no guarantee that this won't cause problems!



                                                                      What may work better is to NOT do anything that requries root privileges. I would try to create a file in my home directoy named .bash_login and start tmux from within that file: `echo "tmux" >~/.bash_login.



                                                                      This should work, but you have to try and find our yourself, b/c the bash documentation is not very exact about what file is read and executed when.







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Jul 20 '12 at 17:42









                                                                      Bananguin

                                                                      5,2451338




                                                                      5,2451338








                                                                      • 2




                                                                        What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins.
                                                                        – Gilles
                                                                        Jul 20 '12 at 23:10














                                                                      • 2




                                                                        What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins.
                                                                        – Gilles
                                                                        Jul 20 '12 at 23:10








                                                                      2




                                                                      2




                                                                      What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins.
                                                                      – Gilles
                                                                      Jul 20 '12 at 23:10




                                                                      What your first paragraph describes is what chsh does! Except that your way requires being root and is error-prone. Running tmux from .bash_login is more likely to break remote logins.
                                                                      – Gilles
                                                                      Jul 20 '12 at 23:10


















                                                                      draft saved

                                                                      draft discarded




















































                                                                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                                      • Please be sure to answer the question. Provide details and share your research!

                                                                      But avoid



                                                                      • Asking for help, clarification, or responding to other answers.

                                                                      • Making statements based on opinion; back them up with references or personal experience.


                                                                      To learn more, see our tips on writing great answers.





                                                                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                      Please pay close attention to the following guidance:


                                                                      • Please be sure to answer the question. Provide details and share your research!

                                                                      But avoid



                                                                      • Asking for help, clarification, or responding to other answers.

                                                                      • Making statements based on opinion; back them up with references or personal experience.


                                                                      To learn more, see our tips on writing great answers.




                                                                      draft saved


                                                                      draft discarded














                                                                      StackExchange.ready(
                                                                      function () {
                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f43601%2fhow-can-i-set-my-default-shell-to-start-up-tmux%23new-answer', 'question_page');
                                                                      }
                                                                      );

                                                                      Post as a guest















                                                                      Required, but never shown





















































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown

































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown







                                                                      Popular posts from this blog

                                                                      Morgemoulin

                                                                      Scott Moir

                                                                      Souastre