using screen to split the terminal

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











up vote
0
down vote

favorite












In a bash script I want to show the user a file with less, but I don't want less to take up the whole terminal: I need to keep some informations visible in the terminal while the user browses the file with less.



I googled for terminal split linux and all the results refer to the screen command.



After several hours of trials end errors I believe I've come up with a mostly working solution. I've created a screen.rc file containing:



split
screen 1 less /etc/passwd
focus down
resize 10
screen 2
exec !.. echo Informations area
focus up


Now, in my bash script, I can run



screen -c screen.rc


and it creates a split terminal with less /etc/passwd output in the top region and Information area in the bottom one and the top region is receiving user input, which is exactly the intended behavior. Almost perfect, except when the user hits q to terminate less, screen does not terminate, because there's still a running shell in the bottom region. The user now needs to focus the bottom region (CTRL+a TAB) and hit Ctrl+d to terminate the running bash.



So the sequence to exit my custom less file viewer has now become q CTRL+a TAB CTRL+d: quite a lot of keystrokes only to exit a text file viewer...



How can I make screen terminate immediately when the top region less command quits?







share|improve this question























    up vote
    0
    down vote

    favorite












    In a bash script I want to show the user a file with less, but I don't want less to take up the whole terminal: I need to keep some informations visible in the terminal while the user browses the file with less.



    I googled for terminal split linux and all the results refer to the screen command.



    After several hours of trials end errors I believe I've come up with a mostly working solution. I've created a screen.rc file containing:



    split
    screen 1 less /etc/passwd
    focus down
    resize 10
    screen 2
    exec !.. echo Informations area
    focus up


    Now, in my bash script, I can run



    screen -c screen.rc


    and it creates a split terminal with less /etc/passwd output in the top region and Information area in the bottom one and the top region is receiving user input, which is exactly the intended behavior. Almost perfect, except when the user hits q to terminate less, screen does not terminate, because there's still a running shell in the bottom region. The user now needs to focus the bottom region (CTRL+a TAB) and hit Ctrl+d to terminate the running bash.



    So the sequence to exit my custom less file viewer has now become q CTRL+a TAB CTRL+d: quite a lot of keystrokes only to exit a text file viewer...



    How can I make screen terminate immediately when the top region less command quits?







    share|improve this question





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      In a bash script I want to show the user a file with less, but I don't want less to take up the whole terminal: I need to keep some informations visible in the terminal while the user browses the file with less.



      I googled for terminal split linux and all the results refer to the screen command.



      After several hours of trials end errors I believe I've come up with a mostly working solution. I've created a screen.rc file containing:



      split
      screen 1 less /etc/passwd
      focus down
      resize 10
      screen 2
      exec !.. echo Informations area
      focus up


      Now, in my bash script, I can run



      screen -c screen.rc


      and it creates a split terminal with less /etc/passwd output in the top region and Information area in the bottom one and the top region is receiving user input, which is exactly the intended behavior. Almost perfect, except when the user hits q to terminate less, screen does not terminate, because there's still a running shell in the bottom region. The user now needs to focus the bottom region (CTRL+a TAB) and hit Ctrl+d to terminate the running bash.



      So the sequence to exit my custom less file viewer has now become q CTRL+a TAB CTRL+d: quite a lot of keystrokes only to exit a text file viewer...



      How can I make screen terminate immediately when the top region less command quits?







      share|improve this question











      In a bash script I want to show the user a file with less, but I don't want less to take up the whole terminal: I need to keep some informations visible in the terminal while the user browses the file with less.



      I googled for terminal split linux and all the results refer to the screen command.



      After several hours of trials end errors I believe I've come up with a mostly working solution. I've created a screen.rc file containing:



      split
      screen 1 less /etc/passwd
      focus down
      resize 10
      screen 2
      exec !.. echo Informations area
      focus up


      Now, in my bash script, I can run



      screen -c screen.rc


      and it creates a split terminal with less /etc/passwd output in the top region and Information area in the bottom one and the top region is receiving user input, which is exactly the intended behavior. Almost perfect, except when the user hits q to terminate less, screen does not terminate, because there's still a running shell in the bottom region. The user now needs to focus the bottom region (CTRL+a TAB) and hit Ctrl+d to terminate the running bash.



      So the sequence to exit my custom less file viewer has now become q CTRL+a TAB CTRL+d: quite a lot of keystrokes only to exit a text file viewer...



      How can I make screen terminate immediately when the top region less command quits?









      share|improve this question










      share|improve this question




      share|improve this question









      asked May 8 at 22:59









      Lucio Crusca

      1034




      1034




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Sending the quit command will tell screen to quit, so replace the less command with:



          screen 1 sh -c 'less /etc/passwd ; screen -S "$STY" -X quit'


          or something to that effect.






          share|improve this answer





















          • can you please explain that "$STY"? Thanks.
            – Lucio Crusca
            May 8 at 23:38










          • STY – Alternate socket name.
            – Ignacio Vazquez-Abrams
            May 8 at 23:45










          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f442646%2fusing-screen-to-split-the-terminal%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Sending the quit command will tell screen to quit, so replace the less command with:



          screen 1 sh -c 'less /etc/passwd ; screen -S "$STY" -X quit'


          or something to that effect.






          share|improve this answer





















          • can you please explain that "$STY"? Thanks.
            – Lucio Crusca
            May 8 at 23:38










          • STY – Alternate socket name.
            – Ignacio Vazquez-Abrams
            May 8 at 23:45














          up vote
          1
          down vote



          accepted










          Sending the quit command will tell screen to quit, so replace the less command with:



          screen 1 sh -c 'less /etc/passwd ; screen -S "$STY" -X quit'


          or something to that effect.






          share|improve this answer





















          • can you please explain that "$STY"? Thanks.
            – Lucio Crusca
            May 8 at 23:38










          • STY – Alternate socket name.
            – Ignacio Vazquez-Abrams
            May 8 at 23:45












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Sending the quit command will tell screen to quit, so replace the less command with:



          screen 1 sh -c 'less /etc/passwd ; screen -S "$STY" -X quit'


          or something to that effect.






          share|improve this answer













          Sending the quit command will tell screen to quit, so replace the less command with:



          screen 1 sh -c 'less /etc/passwd ; screen -S "$STY" -X quit'


          or something to that effect.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered May 8 at 23:14









          Ignacio Vazquez-Abrams

          32k66780




          32k66780











          • can you please explain that "$STY"? Thanks.
            – Lucio Crusca
            May 8 at 23:38










          • STY – Alternate socket name.
            – Ignacio Vazquez-Abrams
            May 8 at 23:45
















          • can you please explain that "$STY"? Thanks.
            – Lucio Crusca
            May 8 at 23:38










          • STY – Alternate socket name.
            – Ignacio Vazquez-Abrams
            May 8 at 23:45















          can you please explain that "$STY"? Thanks.
          – Lucio Crusca
          May 8 at 23:38




          can you please explain that "$STY"? Thanks.
          – Lucio Crusca
          May 8 at 23:38












          STY – Alternate socket name.
          – Ignacio Vazquez-Abrams
          May 8 at 23:45




          STY – Alternate socket name.
          – Ignacio Vazquez-Abrams
          May 8 at 23:45












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442646%2fusing-screen-to-split-the-terminal%23new-answer', 'question_page');

          );

          Post as a guest













































































          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