fish shell - run command based on exit status of previous command












0















My goal is to have a monitor setup, that is as flexible and easy to use as possible. I use fish as my shell and have added the following two lines:



abbr mon 'xrandr --output DP2 --auto --primary --left-of eDP1 || xrandr --output HDMI1 --auto --primary --left-of eDP1 && setxkbmap -layout de -option ctrl:nocaps && i3-msg restart'
abbr moff 'xrandr --output DP2 --off || xrandr --output HDMI1 --off && i3-msg restart'


Which should enable me to just type mon or moff whenever i want to switch my monitor on or off (also the setxkbmap part, because i mainly use a dongle with monitor and keyboard attached to it).



With my understanding concatenating two commands with && runs the second command when the first has succeeded, while concatenating two commands with || only runs the command, when the first command failed.



However in my case the part after && would be run always, because one of the commands should succeed, which it does. See:



tim@arch ~> false || true && echo hello
hello
tim@arch ~> true || false && echo hello
hello


My issue is, that the part after || in my strings never gets run, so the command does nothing, when HDMI1 is connected while DP2 is disconnected.



Why is that? Have i gotten something wrong here?










share|improve this question



























    0















    My goal is to have a monitor setup, that is as flexible and easy to use as possible. I use fish as my shell and have added the following two lines:



    abbr mon 'xrandr --output DP2 --auto --primary --left-of eDP1 || xrandr --output HDMI1 --auto --primary --left-of eDP1 && setxkbmap -layout de -option ctrl:nocaps && i3-msg restart'
    abbr moff 'xrandr --output DP2 --off || xrandr --output HDMI1 --off && i3-msg restart'


    Which should enable me to just type mon or moff whenever i want to switch my monitor on or off (also the setxkbmap part, because i mainly use a dongle with monitor and keyboard attached to it).



    With my understanding concatenating two commands with && runs the second command when the first has succeeded, while concatenating two commands with || only runs the command, when the first command failed.



    However in my case the part after && would be run always, because one of the commands should succeed, which it does. See:



    tim@arch ~> false || true && echo hello
    hello
    tim@arch ~> true || false && echo hello
    hello


    My issue is, that the part after || in my strings never gets run, so the command does nothing, when HDMI1 is connected while DP2 is disconnected.



    Why is that? Have i gotten something wrong here?










    share|improve this question

























      0












      0








      0








      My goal is to have a monitor setup, that is as flexible and easy to use as possible. I use fish as my shell and have added the following two lines:



      abbr mon 'xrandr --output DP2 --auto --primary --left-of eDP1 || xrandr --output HDMI1 --auto --primary --left-of eDP1 && setxkbmap -layout de -option ctrl:nocaps && i3-msg restart'
      abbr moff 'xrandr --output DP2 --off || xrandr --output HDMI1 --off && i3-msg restart'


      Which should enable me to just type mon or moff whenever i want to switch my monitor on or off (also the setxkbmap part, because i mainly use a dongle with monitor and keyboard attached to it).



      With my understanding concatenating two commands with && runs the second command when the first has succeeded, while concatenating two commands with || only runs the command, when the first command failed.



      However in my case the part after && would be run always, because one of the commands should succeed, which it does. See:



      tim@arch ~> false || true && echo hello
      hello
      tim@arch ~> true || false && echo hello
      hello


      My issue is, that the part after || in my strings never gets run, so the command does nothing, when HDMI1 is connected while DP2 is disconnected.



      Why is that? Have i gotten something wrong here?










      share|improve this question














      My goal is to have a monitor setup, that is as flexible and easy to use as possible. I use fish as my shell and have added the following two lines:



      abbr mon 'xrandr --output DP2 --auto --primary --left-of eDP1 || xrandr --output HDMI1 --auto --primary --left-of eDP1 && setxkbmap -layout de -option ctrl:nocaps && i3-msg restart'
      abbr moff 'xrandr --output DP2 --off || xrandr --output HDMI1 --off && i3-msg restart'


      Which should enable me to just type mon or moff whenever i want to switch my monitor on or off (also the setxkbmap part, because i mainly use a dongle with monitor and keyboard attached to it).



      With my understanding concatenating two commands with && runs the second command when the first has succeeded, while concatenating two commands with || only runs the command, when the first command failed.



      However in my case the part after && would be run always, because one of the commands should succeed, which it does. See:



      tim@arch ~> false || true && echo hello
      hello
      tim@arch ~> true || false && echo hello
      hello


      My issue is, that the part after || in my strings never gets run, so the command does nothing, when HDMI1 is connected while DP2 is disconnected.



      Why is that? Have i gotten something wrong here?







      concatenation xrandr conditional-statements exit-code






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 15 at 15:51









      Tim HiltTim Hilt

      4717




      4717






















          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%2f1406150%2ffish-shell-run-command-based-on-exit-status-of-previous-command%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%2f1406150%2ffish-shell-run-command-based-on-exit-status-of-previous-command%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

          flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

          Mangá

           ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕