If named tmux session exists, make new session and group with it, else create that named tmux sessiontmux and...

Why is "points exist" not an axiom in geometry?

Where are a monster’s hit dice found in the stat block?

What creature do these Alchemical Homunculus actions target?

Why are the books in the Game of Thrones citadel library shelved spine inwards?

Disable the ">" operator in Rstudio linux terminal

A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?

If I delete my router's history can my ISP still provide it to my parents?

Would a National Army of mercenaries be a feasible idea?

Would these multi-classing house rules cause unintended problems?

Typing Amharic inside a math equation?

Show that the following sequence converges. Please Critique my proof.

Can you earn endless XP using a Flameskull and its self-revival feature?

Word or phrase for showing great skill at something without formal training in it

What is this metal M-shaped device for?

Enable Advanced Currency Management using CLI

What to do when being responsible for data protection in your lab, yet advice is ignored?

What does Cypher mean when he says Neo is "gonna pop"?

How do I say "Brexit" in Latin?

Why would the Pakistan airspace closure cancel flights not headed to Pakistan itself?

Isn't using the Extrusion Multiplier like cheating?

Cryptic with missing capitals

How should I handle players who ignore the session zero agreement?

Quenching swords in dragon blood; why?

Solving Fredholm Equation of the second kind



If named tmux session exists, make new session and group with it, else create that named tmux session


tmux and text selection with mouse through puttyTmux new named session exitedStart tmux session with only one window but several panesDisallowing windows to rename themselves in tmuxIn tmux, can I get `exit` to exit the containing terminal window and not the session itself?Start a new session from within tmux with ZSH_TMUX_AUTOSTART=trueHow to source a script in every panes and windows of a specific tmux sessionHow to keep terminal window title in sync with tmux windowHow to make tmux kill session as normal on terminal exitTmux starting a second session upon startup with .tmux.conf file













0















What I Want



I'm trying to automate connecting to a remote machine in multiple, seperate ssh terminals and have independent tmux sessions for each remote terminal while sharing the same windows (i.e. can change session settings and active window/pane without affecting other remote terminals while still having access to the same tmux windows).



I want to do this without changing how the tmux executable is initially run and entirely in a per-user way (all changes limited to /home/$USER/).



How I'm Trying To Accomplish It



Ubuntu 16.04
TMUX 2.1 (from package manager)



I'm using MS's port of ssh (OpenSSH) on my local system (Windows 10).



Currently when I open a remote terminal (or a local terminal for that matter) tmux is launched via /etc/profile.d/ and creates an entirely new session. I have a ~/.tmux.conf file with the following line:



#(this is a single line in my .tmux.conf, I've broken it up here for readability)

if-shell 'tmux has-session -t theonering'
'new-session -t theonering'
'rename-session theonering'


I'm, also setting destroy-unattached on at the session level in that second line, but I left it out for clarity here. It doesn't change the outcome.



What I Expect To Happen



This states, to the best of my understanding (see Documentation below), that "if, from a shell, tmux says it has a session named theonering then create a new (unnamed) session and group it with theonering. if tmux does not have a session named theonering renamed the current session to theonering."



What Actually Happens



Now if I connect remotely, detach from the existing session, then run the above command (prefixed with tmux, obviously)? Works great.



But if I put it in my ~/.tmux.conf? bupkiss. It's the same as if the line wasn't there at all. No error, no message, no deviation from stock behavior.



Documentation



if-shell from the tmux manpage:




if-shell [-bF] [-t target-pane] shell-command command [command]




Execute the first command if shell-command returns success or the second command otherwise. Before being executed, shell-command is expanded using the rules specified in the FORMATS section, including those relevant to target-pane. With -b, shell-command is run in the background.



If -F is given, shell-command is not executed but considered success if neither empty nor zero (after formats are expanded).





How to determine if the session exists:




has-session [-t target-session]




Report an error and exit with 1 if the specified session does not exist. If it does exist, exit with 0.





How to create a new session that groups with the existing session:




new-session [-AdDEP] [-c start-directory] [-F format] [-n window-name] [-s session-name] [-t target-session] [-x width] [-y height] [shell-command]




Create a new session with name session-name.



The new session is attached to the current terminal unless -d is given. window-name and shell-command are the name of and shell command to execute in the initial window. If -d is used, -x and -y specify the size of the initial window (80 by 24 if not given).



If run from a terminal, any termios(3) special characters are saved and used for new windows in the new session.



The -A flag makes new-session behave like attach-session if session-name already exists; in this case, -D behaves like -d to attach-session.



If -t is given, the new session is grouped with target-session. This means they share the same set of windows - all windows from target-session are linked to the new session and any subsequent new windows or windows being closed are applied to both sessions. The current and previous window and any session options remain independent and either session may be killed without affecting the other. Giving -n or shell-command are invalid if -t is used.



The -P option prints information about the new session after it has been created. By default, it uses the format ‘#{session_name}:’ but a different format may be specified with -F.



If -E is used, update-environment option will not be applied. update-environment.





How to rename the current session:




rename-session [-t target-session] new-name




Rename the session to new-name.





And, of course, I'm assuming if-shell treats exit code 0 as "success" and any other exit code as "otherwise".









share



























    0















    What I Want



    I'm trying to automate connecting to a remote machine in multiple, seperate ssh terminals and have independent tmux sessions for each remote terminal while sharing the same windows (i.e. can change session settings and active window/pane without affecting other remote terminals while still having access to the same tmux windows).



    I want to do this without changing how the tmux executable is initially run and entirely in a per-user way (all changes limited to /home/$USER/).



    How I'm Trying To Accomplish It



    Ubuntu 16.04
    TMUX 2.1 (from package manager)



    I'm using MS's port of ssh (OpenSSH) on my local system (Windows 10).



    Currently when I open a remote terminal (or a local terminal for that matter) tmux is launched via /etc/profile.d/ and creates an entirely new session. I have a ~/.tmux.conf file with the following line:



    #(this is a single line in my .tmux.conf, I've broken it up here for readability)

    if-shell 'tmux has-session -t theonering'
    'new-session -t theonering'
    'rename-session theonering'


    I'm, also setting destroy-unattached on at the session level in that second line, but I left it out for clarity here. It doesn't change the outcome.



    What I Expect To Happen



    This states, to the best of my understanding (see Documentation below), that "if, from a shell, tmux says it has a session named theonering then create a new (unnamed) session and group it with theonering. if tmux does not have a session named theonering renamed the current session to theonering."



    What Actually Happens



    Now if I connect remotely, detach from the existing session, then run the above command (prefixed with tmux, obviously)? Works great.



    But if I put it in my ~/.tmux.conf? bupkiss. It's the same as if the line wasn't there at all. No error, no message, no deviation from stock behavior.



    Documentation



    if-shell from the tmux manpage:




    if-shell [-bF] [-t target-pane] shell-command command [command]




    Execute the first command if shell-command returns success or the second command otherwise. Before being executed, shell-command is expanded using the rules specified in the FORMATS section, including those relevant to target-pane. With -b, shell-command is run in the background.



    If -F is given, shell-command is not executed but considered success if neither empty nor zero (after formats are expanded).





    How to determine if the session exists:




    has-session [-t target-session]




    Report an error and exit with 1 if the specified session does not exist. If it does exist, exit with 0.





    How to create a new session that groups with the existing session:




    new-session [-AdDEP] [-c start-directory] [-F format] [-n window-name] [-s session-name] [-t target-session] [-x width] [-y height] [shell-command]




    Create a new session with name session-name.



    The new session is attached to the current terminal unless -d is given. window-name and shell-command are the name of and shell command to execute in the initial window. If -d is used, -x and -y specify the size of the initial window (80 by 24 if not given).



    If run from a terminal, any termios(3) special characters are saved and used for new windows in the new session.



    The -A flag makes new-session behave like attach-session if session-name already exists; in this case, -D behaves like -d to attach-session.



    If -t is given, the new session is grouped with target-session. This means they share the same set of windows - all windows from target-session are linked to the new session and any subsequent new windows or windows being closed are applied to both sessions. The current and previous window and any session options remain independent and either session may be killed without affecting the other. Giving -n or shell-command are invalid if -t is used.



    The -P option prints information about the new session after it has been created. By default, it uses the format ‘#{session_name}:’ but a different format may be specified with -F.



    If -E is used, update-environment option will not be applied. update-environment.





    How to rename the current session:




    rename-session [-t target-session] new-name




    Rename the session to new-name.





    And, of course, I'm assuming if-shell treats exit code 0 as "success" and any other exit code as "otherwise".









    share

























      0












      0








      0








      What I Want



      I'm trying to automate connecting to a remote machine in multiple, seperate ssh terminals and have independent tmux sessions for each remote terminal while sharing the same windows (i.e. can change session settings and active window/pane without affecting other remote terminals while still having access to the same tmux windows).



      I want to do this without changing how the tmux executable is initially run and entirely in a per-user way (all changes limited to /home/$USER/).



      How I'm Trying To Accomplish It



      Ubuntu 16.04
      TMUX 2.1 (from package manager)



      I'm using MS's port of ssh (OpenSSH) on my local system (Windows 10).



      Currently when I open a remote terminal (or a local terminal for that matter) tmux is launched via /etc/profile.d/ and creates an entirely new session. I have a ~/.tmux.conf file with the following line:



      #(this is a single line in my .tmux.conf, I've broken it up here for readability)

      if-shell 'tmux has-session -t theonering'
      'new-session -t theonering'
      'rename-session theonering'


      I'm, also setting destroy-unattached on at the session level in that second line, but I left it out for clarity here. It doesn't change the outcome.



      What I Expect To Happen



      This states, to the best of my understanding (see Documentation below), that "if, from a shell, tmux says it has a session named theonering then create a new (unnamed) session and group it with theonering. if tmux does not have a session named theonering renamed the current session to theonering."



      What Actually Happens



      Now if I connect remotely, detach from the existing session, then run the above command (prefixed with tmux, obviously)? Works great.



      But if I put it in my ~/.tmux.conf? bupkiss. It's the same as if the line wasn't there at all. No error, no message, no deviation from stock behavior.



      Documentation



      if-shell from the tmux manpage:




      if-shell [-bF] [-t target-pane] shell-command command [command]




      Execute the first command if shell-command returns success or the second command otherwise. Before being executed, shell-command is expanded using the rules specified in the FORMATS section, including those relevant to target-pane. With -b, shell-command is run in the background.



      If -F is given, shell-command is not executed but considered success if neither empty nor zero (after formats are expanded).





      How to determine if the session exists:




      has-session [-t target-session]




      Report an error and exit with 1 if the specified session does not exist. If it does exist, exit with 0.





      How to create a new session that groups with the existing session:




      new-session [-AdDEP] [-c start-directory] [-F format] [-n window-name] [-s session-name] [-t target-session] [-x width] [-y height] [shell-command]




      Create a new session with name session-name.



      The new session is attached to the current terminal unless -d is given. window-name and shell-command are the name of and shell command to execute in the initial window. If -d is used, -x and -y specify the size of the initial window (80 by 24 if not given).



      If run from a terminal, any termios(3) special characters are saved and used for new windows in the new session.



      The -A flag makes new-session behave like attach-session if session-name already exists; in this case, -D behaves like -d to attach-session.



      If -t is given, the new session is grouped with target-session. This means they share the same set of windows - all windows from target-session are linked to the new session and any subsequent new windows or windows being closed are applied to both sessions. The current and previous window and any session options remain independent and either session may be killed without affecting the other. Giving -n or shell-command are invalid if -t is used.



      The -P option prints information about the new session after it has been created. By default, it uses the format ‘#{session_name}:’ but a different format may be specified with -F.



      If -E is used, update-environment option will not be applied. update-environment.





      How to rename the current session:




      rename-session [-t target-session] new-name




      Rename the session to new-name.





      And, of course, I'm assuming if-shell treats exit code 0 as "success" and any other exit code as "otherwise".









      share














      What I Want



      I'm trying to automate connecting to a remote machine in multiple, seperate ssh terminals and have independent tmux sessions for each remote terminal while sharing the same windows (i.e. can change session settings and active window/pane without affecting other remote terminals while still having access to the same tmux windows).



      I want to do this without changing how the tmux executable is initially run and entirely in a per-user way (all changes limited to /home/$USER/).



      How I'm Trying To Accomplish It



      Ubuntu 16.04
      TMUX 2.1 (from package manager)



      I'm using MS's port of ssh (OpenSSH) on my local system (Windows 10).



      Currently when I open a remote terminal (or a local terminal for that matter) tmux is launched via /etc/profile.d/ and creates an entirely new session. I have a ~/.tmux.conf file with the following line:



      #(this is a single line in my .tmux.conf, I've broken it up here for readability)

      if-shell 'tmux has-session -t theonering'
      'new-session -t theonering'
      'rename-session theonering'


      I'm, also setting destroy-unattached on at the session level in that second line, but I left it out for clarity here. It doesn't change the outcome.



      What I Expect To Happen



      This states, to the best of my understanding (see Documentation below), that "if, from a shell, tmux says it has a session named theonering then create a new (unnamed) session and group it with theonering. if tmux does not have a session named theonering renamed the current session to theonering."



      What Actually Happens



      Now if I connect remotely, detach from the existing session, then run the above command (prefixed with tmux, obviously)? Works great.



      But if I put it in my ~/.tmux.conf? bupkiss. It's the same as if the line wasn't there at all. No error, no message, no deviation from stock behavior.



      Documentation



      if-shell from the tmux manpage:




      if-shell [-bF] [-t target-pane] shell-command command [command]




      Execute the first command if shell-command returns success or the second command otherwise. Before being executed, shell-command is expanded using the rules specified in the FORMATS section, including those relevant to target-pane. With -b, shell-command is run in the background.



      If -F is given, shell-command is not executed but considered success if neither empty nor zero (after formats are expanded).





      How to determine if the session exists:




      has-session [-t target-session]




      Report an error and exit with 1 if the specified session does not exist. If it does exist, exit with 0.





      How to create a new session that groups with the existing session:




      new-session [-AdDEP] [-c start-directory] [-F format] [-n window-name] [-s session-name] [-t target-session] [-x width] [-y height] [shell-command]




      Create a new session with name session-name.



      The new session is attached to the current terminal unless -d is given. window-name and shell-command are the name of and shell command to execute in the initial window. If -d is used, -x and -y specify the size of the initial window (80 by 24 if not given).



      If run from a terminal, any termios(3) special characters are saved and used for new windows in the new session.



      The -A flag makes new-session behave like attach-session if session-name already exists; in this case, -D behaves like -d to attach-session.



      If -t is given, the new session is grouped with target-session. This means they share the same set of windows - all windows from target-session are linked to the new session and any subsequent new windows or windows being closed are applied to both sessions. The current and previous window and any session options remain independent and either session may be killed without affecting the other. Giving -n or shell-command are invalid if -t is used.



      The -P option prints information about the new session after it has been created. By default, it uses the format ‘#{session_name}:’ but a different format may be specified with -F.



      If -E is used, update-environment option will not be applied. update-environment.





      How to rename the current session:




      rename-session [-t target-session] new-name




      Rename the session to new-name.





      And, of course, I'm assuming if-shell treats exit code 0 as "success" and any other exit code as "otherwise".







      ubuntu ssh tmux





      share












      share










      share



      share










      asked 6 mins ago









      Cliff ArmstrongCliff Armstrong

      1,222112




      1,222112






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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%2fsuperuser.com%2fquestions%2f1410640%2fif-named-tmux-session-exists-make-new-session-and-group-with-it-else-create-th%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • 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%2fsuperuser.com%2fquestions%2f1410640%2fif-named-tmux-session-exists-make-new-session-and-group-with-it-else-create-th%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

          VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

          Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

          looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...