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

Clash 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
fishis not available; - in general, as
fishis not POSIX-sh compatible putting it as default shell may break commands executed by scripts throughssh; - 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
add a comment |Â
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
fishis not available; - in general, as
fishis not POSIX-sh compatible putting it as default shell may break commands executed by scripts throughssh; - 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
add a comment |Â
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
fishis not available; - in general, as
fishis not POSIX-sh compatible putting it as default shell may break commands executed by scripts throughssh; - 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
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
fishis not available; - in general, as
fishis not POSIX-sh compatible putting it as default shell may break commands executed by scripts throughssh; - 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
shell ssh login fish
asked 8 mins ago
Matteo Italia
37929
37929
add a comment |Â
add a comment |Â
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 tossh-tforces the allocation of a tty (otherwisesshdefaults to no tty when a command is specified)sh -cis required because we don't know what shell we may have on the other side - on my personal machines I do havefishas default shell;which fishsucceeds if it finds an executablefish; in that case, it isexec-ed;- otherwise, we fall back to
$SHELL, which is the default shell for the current user ($is escaped otherwise it gets expanded bysh"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.
add a comment |Â
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 tossh-tforces the allocation of a tty (otherwisesshdefaults to no tty when a command is specified)sh -cis required because we don't know what shell we may have on the other side - on my personal machines I do havefishas default shell;which fishsucceeds if it finds an executablefish; in that case, it isexec-ed;- otherwise, we fall back to
$SHELL, which is the default shell for the current user ($is escaped otherwise it gets expanded bysh"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.
add a comment |Â
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 tossh-tforces the allocation of a tty (otherwisesshdefaults to no tty when a command is specified)sh -cis required because we don't know what shell we may have on the other side - on my personal machines I do havefishas default shell;which fishsucceeds if it finds an executablefish; in that case, it isexec-ed;- otherwise, we fall back to
$SHELL, which is the default shell for the current user ($is escaped otherwise it gets expanded bysh"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.
add a comment |Â
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 tossh-tforces the allocation of a tty (otherwisesshdefaults to no tty when a command is specified)sh -cis required because we don't know what shell we may have on the other side - on my personal machines I do havefishas default shell;which fishsucceeds if it finds an executablefish; in that case, it isexec-ed;- otherwise, we fall back to
$SHELL, which is the default shell for the current user ($is escaped otherwise it gets expanded bysh"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.
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 tossh-tforces the allocation of a tty (otherwisesshdefaults to no tty when a command is specified)sh -cis required because we don't know what shell we may have on the other side - on my personal machines I do havefishas default shell;which fishsucceeds if it finds an executablefish; in that case, it isexec-ed;- otherwise, we fall back to
$SHELL, which is the default shell for the current user ($is escaped otherwise it gets expanded bysh"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.
answered 8 mins ago
Matteo Italia
37929
37929
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password