How to properly launch tmux on terminal startup?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












7















I've used this snippet to launch tmux when the terminal is launched:



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


But with this I can't exit tmux without the terminal screen being closed too.



I've tried:



Ctrl + b :detach



exit



And looking for the PID and killing it. All those methods close the terminal too.



How should I configure tmux to start when launching the terminal but still being able to close it without the terminal closing? Any tips are appreciated!










share|improve this question
























  • I've just tried and replacing the snipped I used with just tmux works, but I get a: sessions should be nested with care, unset $TMUX to force. I've also tried leaving the snipped I used as it is and adding a tmux at the end of the ~/.bashrc but then detaching still exits the terminal.

    – bpinaya
    Feb 19 at 10:37















7















I've used this snippet to launch tmux when the terminal is launched:



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


But with this I can't exit tmux without the terminal screen being closed too.



I've tried:



Ctrl + b :detach



exit



And looking for the PID and killing it. All those methods close the terminal too.



How should I configure tmux to start when launching the terminal but still being able to close it without the terminal closing? Any tips are appreciated!










share|improve this question
























  • I've just tried and replacing the snipped I used with just tmux works, but I get a: sessions should be nested with care, unset $TMUX to force. I've also tried leaving the snipped I used as it is and adding a tmux at the end of the ~/.bashrc but then detaching still exits the terminal.

    – bpinaya
    Feb 19 at 10:37













7












7








7


1






I've used this snippet to launch tmux when the terminal is launched:



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


But with this I can't exit tmux without the terminal screen being closed too.



I've tried:



Ctrl + b :detach



exit



And looking for the PID and killing it. All those methods close the terminal too.



How should I configure tmux to start when launching the terminal but still being able to close it without the terminal closing? Any tips are appreciated!










share|improve this question
















I've used this snippet to launch tmux when the terminal is launched:



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


But with this I can't exit tmux without the terminal screen being closed too.



I've tried:



Ctrl + b :detach



exit



And looking for the PID and killing it. All those methods close the terminal too.



How should I configure tmux to start when launching the terminal but still being able to close it without the terminal closing? Any tips are appreciated!







command-line bash shortcut-keys bashrc tmux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 19 at 10:26









dessert

24.6k672105




24.6k672105










asked Feb 19 at 10:25









bpinayabpinaya

608




608












  • I've just tried and replacing the snipped I used with just tmux works, but I get a: sessions should be nested with care, unset $TMUX to force. I've also tried leaving the snipped I used as it is and adding a tmux at the end of the ~/.bashrc but then detaching still exits the terminal.

    – bpinaya
    Feb 19 at 10:37

















  • I've just tried and replacing the snipped I used with just tmux works, but I get a: sessions should be nested with care, unset $TMUX to force. I've also tried leaving the snipped I used as it is and adding a tmux at the end of the ~/.bashrc but then detaching still exits the terminal.

    – bpinaya
    Feb 19 at 10:37
















I've just tried and replacing the snipped I used with just tmux works, but I get a: sessions should be nested with care, unset $TMUX to force. I've also tried leaving the snipped I used as it is and adding a tmux at the end of the ~/.bashrc but then detaching still exits the terminal.

– bpinaya
Feb 19 at 10:37





I've just tried and replacing the snipped I used with just tmux works, but I get a: sessions should be nested with care, unset $TMUX to force. I've also tried leaving the snipped I used as it is and adding a tmux at the end of the ~/.bashrc but then detaching still exits the terminal.

– bpinaya
Feb 19 at 10:37










1 Answer
1






active

oldest

votes


















9














The problem is the exec command. As explained here, exec will replace the current shell with whatever you tell it execute. So you don't have a shell that is running tmux, you just have tmux and therefore exiting it will also exit the terminal.



Just remove the exec and it should work as expected:



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





share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2faskubuntu.com%2fquestions%2f1119478%2fhow-to-properly-launch-tmux-on-terminal-startup%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9














    The problem is the exec command. As explained here, exec will replace the current shell with whatever you tell it execute. So you don't have a shell that is running tmux, you just have tmux and therefore exiting it will also exit the terminal.



    Just remove the exec and it should work as expected:



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





    share|improve this answer



























      9














      The problem is the exec command. As explained here, exec will replace the current shell with whatever you tell it execute. So you don't have a shell that is running tmux, you just have tmux and therefore exiting it will also exit the terminal.



      Just remove the exec and it should work as expected:



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





      share|improve this answer

























        9












        9








        9







        The problem is the exec command. As explained here, exec will replace the current shell with whatever you tell it execute. So you don't have a shell that is running tmux, you just have tmux and therefore exiting it will also exit the terminal.



        Just remove the exec and it should work as expected:



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





        share|improve this answer













        The problem is the exec command. As explained here, exec will replace the current shell with whatever you tell it execute. So you don't have a shell that is running tmux, you just have tmux and therefore exiting it will also exit the terminal.



        Just remove the exec and it should work as expected:



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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 19 at 11:21









        terdonterdon

        67k13139221




        67k13139221



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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%2faskubuntu.com%2fquestions%2f1119478%2fhow-to-properly-launch-tmux-on-terminal-startup%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

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay