How to use fish on remote servers that have it installed without changing login shell?

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











up vote
1
down vote

favorite












I regularly ssh on several different servers, some of which don't have fish installed, but many do. I'd like to get fish as shell if available (changing midway is always tedious, and you lose the history of what you already typed), but changing the default shell is not a good idea, as:



  • there are many different machines that I would need to change;

  • on many other I'm logged in through LDAP, and changing my shell as stored on LDAP would break on machines where fish is not available;

  • in general, as fish is not POSIX-sh compatible putting it as default shell may break commands executed by scripts through ssh;

  • finally, there are a few machines where the user is shared with other people (or, where I have to login another user), so changing the default shell is not a good idea.

So, ideally I'd like to have a command like ssh that automagically starts fish if available, or just leave whatever default shell is provided otherwise.









share

























    up vote
    1
    down vote

    favorite












    I regularly ssh on several different servers, some of which don't have fish installed, but many do. I'd like to get fish as shell if available (changing midway is always tedious, and you lose the history of what you already typed), but changing the default shell is not a good idea, as:



    • there are many different machines that I would need to change;

    • on many other I'm logged in through LDAP, and changing my shell as stored on LDAP would break on machines where fish is not available;

    • in general, as fish is not POSIX-sh compatible putting it as default shell may break commands executed by scripts through ssh;

    • finally, there are a few machines where the user is shared with other people (or, where I have to login another user), so changing the default shell is not a good idea.

    So, ideally I'd like to have a command like ssh that automagically starts fish if available, or just leave whatever default shell is provided otherwise.









    share























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I regularly ssh on several different servers, some of which don't have fish installed, but many do. I'd like to get fish as shell if available (changing midway is always tedious, and you lose the history of what you already typed), but changing the default shell is not a good idea, as:



      • there are many different machines that I would need to change;

      • on many other I'm logged in through LDAP, and changing my shell as stored on LDAP would break on machines where fish is not available;

      • in general, as fish is not POSIX-sh compatible putting it as default shell may break commands executed by scripts through ssh;

      • finally, there are a few machines where the user is shared with other people (or, where I have to login another user), so changing the default shell is not a good idea.

      So, ideally I'd like to have a command like ssh that automagically starts fish if available, or just leave whatever default shell is provided otherwise.









      share













      I regularly ssh on several different servers, some of which don't have fish installed, but many do. I'd like to get fish as shell if available (changing midway is always tedious, and you lose the history of what you already typed), but changing the default shell is not a good idea, as:



      • there are many different machines that I would need to change;

      • on many other I'm logged in through LDAP, and changing my shell as stored on LDAP would break on machines where fish is not available;

      • in general, as fish is not POSIX-sh compatible putting it as default shell may break commands executed by scripts through ssh;

      • finally, there are a few machines where the user is shared with other people (or, where I have to login another user), so changing the default shell is not a good idea.

      So, ideally I'd like to have a command like ssh that automagically starts fish if available, or just leave whatever default shell is provided otherwise.







      shell ssh login fish





      share












      share










      share



      share










      asked 8 mins ago









      Matteo Italia

      37929




      37929




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          After some experiments, I put together the fissh script:



          #!/bin/sh
          ssh "$@" -t "sh -c 'if which fish >/dev/null ; then exec fish; else exec $SHELL; fi'"



          • "$@" forwards all arguments passed to ssh


          • -t forces the allocation of a tty (otherwise ssh defaults to no tty when a command is specified)


          • sh -c is required because we don't know what shell we may have on the other side - on my personal machines I do have fish as default shell;


          • which fish succeeds if it finds an executable fish; in that case, it is exec-ed;

          • otherwise, we fall back to $SHELL, which is the default shell for the current user ($ is escaped otherwise it gets expanded by sh "on this side").

          Notice that stdout of which is hidden (as in the normal case we don't care about where fish was found), but stderr (where the error message that fish couldn't be found) is intentionally left intact as a warning to the user that, despite our best intentions, fish couldn't be found.



          To complete the experience, on my machines with fish I add the support for customized completion by creating a ~/.config/fish/completions/fissh.fish file containing



          complete -c fissh -w ssh


          to instruct fish that fissh has the exact same valid completions as ssh.





          share




















            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%2f476107%2fhow-to-use-fish-on-remote-servers-that-have-it-installed-without-changing-login%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













            After some experiments, I put together the fissh script:



            #!/bin/sh
            ssh "$@" -t "sh -c 'if which fish >/dev/null ; then exec fish; else exec $SHELL; fi'"



            • "$@" forwards all arguments passed to ssh


            • -t forces the allocation of a tty (otherwise ssh defaults to no tty when a command is specified)


            • sh -c is required because we don't know what shell we may have on the other side - on my personal machines I do have fish as default shell;


            • which fish succeeds if it finds an executable fish; in that case, it is exec-ed;

            • otherwise, we fall back to $SHELL, which is the default shell for the current user ($ is escaped otherwise it gets expanded by sh "on this side").

            Notice that stdout of which is hidden (as in the normal case we don't care about where fish was found), but stderr (where the error message that fish couldn't be found) is intentionally left intact as a warning to the user that, despite our best intentions, fish couldn't be found.



            To complete the experience, on my machines with fish I add the support for customized completion by creating a ~/.config/fish/completions/fissh.fish file containing



            complete -c fissh -w ssh


            to instruct fish that fissh has the exact same valid completions as ssh.





            share
























              up vote
              1
              down vote













              After some experiments, I put together the fissh script:



              #!/bin/sh
              ssh "$@" -t "sh -c 'if which fish >/dev/null ; then exec fish; else exec $SHELL; fi'"



              • "$@" forwards all arguments passed to ssh


              • -t forces the allocation of a tty (otherwise ssh defaults to no tty when a command is specified)


              • sh -c is required because we don't know what shell we may have on the other side - on my personal machines I do have fish as default shell;


              • which fish succeeds if it finds an executable fish; in that case, it is exec-ed;

              • otherwise, we fall back to $SHELL, which is the default shell for the current user ($ is escaped otherwise it gets expanded by sh "on this side").

              Notice that stdout of which is hidden (as in the normal case we don't care about where fish was found), but stderr (where the error message that fish couldn't be found) is intentionally left intact as a warning to the user that, despite our best intentions, fish couldn't be found.



              To complete the experience, on my machines with fish I add the support for customized completion by creating a ~/.config/fish/completions/fissh.fish file containing



              complete -c fissh -w ssh


              to instruct fish that fissh has the exact same valid completions as ssh.





              share






















                up vote
                1
                down vote










                up vote
                1
                down vote









                After some experiments, I put together the fissh script:



                #!/bin/sh
                ssh "$@" -t "sh -c 'if which fish >/dev/null ; then exec fish; else exec $SHELL; fi'"



                • "$@" forwards all arguments passed to ssh


                • -t forces the allocation of a tty (otherwise ssh defaults to no tty when a command is specified)


                • sh -c is required because we don't know what shell we may have on the other side - on my personal machines I do have fish as default shell;


                • which fish succeeds if it finds an executable fish; in that case, it is exec-ed;

                • otherwise, we fall back to $SHELL, which is the default shell for the current user ($ is escaped otherwise it gets expanded by sh "on this side").

                Notice that stdout of which is hidden (as in the normal case we don't care about where fish was found), but stderr (where the error message that fish couldn't be found) is intentionally left intact as a warning to the user that, despite our best intentions, fish couldn't be found.



                To complete the experience, on my machines with fish I add the support for customized completion by creating a ~/.config/fish/completions/fissh.fish file containing



                complete -c fissh -w ssh


                to instruct fish that fissh has the exact same valid completions as ssh.





                share












                After some experiments, I put together the fissh script:



                #!/bin/sh
                ssh "$@" -t "sh -c 'if which fish >/dev/null ; then exec fish; else exec $SHELL; fi'"



                • "$@" forwards all arguments passed to ssh


                • -t forces the allocation of a tty (otherwise ssh defaults to no tty when a command is specified)


                • sh -c is required because we don't know what shell we may have on the other side - on my personal machines I do have fish as default shell;


                • which fish succeeds if it finds an executable fish; in that case, it is exec-ed;

                • otherwise, we fall back to $SHELL, which is the default shell for the current user ($ is escaped otherwise it gets expanded by sh "on this side").

                Notice that stdout of which is hidden (as in the normal case we don't care about where fish was found), but stderr (where the error message that fish couldn't be found) is intentionally left intact as a warning to the user that, despite our best intentions, fish couldn't be found.



                To complete the experience, on my machines with fish I add the support for customized completion by creating a ~/.config/fish/completions/fissh.fish file containing



                complete -c fissh -w ssh


                to instruct fish that fissh has the exact same valid completions as ssh.






                share











                share


                share










                answered 8 mins ago









                Matteo Italia

                37929




                37929



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476107%2fhow-to-use-fish-on-remote-servers-that-have-it-installed-without-changing-login%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    The Forum (Inglewood, California)

                    Palaiologos