I'd like to launch neofetch
(a small utility that displays a banner) each time I log into a remote server via OpenSSH. So, I just added /usr/bin/neofetch
into my ~/.ssh/rc
file, and it works fine.
The problem is that ~/.ssh/rc
is also parsed when I scp
into the server. A complete scp
command works just fine, there is however a problem when I try to use the autocomplete feature of scp
, when I type <Tab><Tab>
so it displays the files/folders available on the remote server, example :
$ scp remote-host:/t <TAB><TAB>
\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\`\\\"\\\"\\\"\\\
\\\ \\\$\\\$\\\:\\\ \\\ \\\ \\\ \\\ \\\ \\\$\\\$.\\\ \\\ \\\ ^[\\\[0m^[\\\[31m^[\\\[1m-^[\\\[0m^[\\\[1m\\\ \\\ \\\ \\\ \\\,d\\\$\\\$\\\'\\\
\\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$b.\\\
\\\ \\\,\\\$\\\$P\\\'\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$\\\$.\\\
\\\ \\\$\\\$P\\\ \\\ \\\ \\\ \\\ \\\ d\\\$\\\'\\\ \\\ \\\ \\\ \\\ ^[\\\[0m^[\\\[31m^[\\\[1m\\\,^[\\\[0m^[\\\[1m\\\ \\\ \\\ \\\ \\\$\\\$P\\\
\\\'\\\,\\\$\\\$P\\\ \\\ \\\ \\\ \\\ \\\ \\\ \\\,ggs.\\\ \\\ \\\ \\\ \\\ \\\`\\\$\\\$b\\\:\\\
\\\ \\\$\\\$\\\;\\\ \\\ \\\ \\\ \\\ \\\ Y\\\$b._\\\ \\\ \\\ _\\\,d\\\$P\\\'\\\
^[\\\[0m^[\\\[1m\\\ \\\`\\\$\\\$b\\\ \\\ \\\ \\\ \\\ \\\ ^[\\\[0m^[\\\[31m^[\\\[1m\\\"-.__\\\
^[\\\[0m^[\\\[1m\\\ \\\ \\\`Y\\\$\\\$\\\
(...)
Usually $ scp remote-host:/t <TAB><TAB>
shows me the files/folders starting with /t
(for example /tmp
), but now it executes the neofetch
banner.
Is there a way to distinguish $ ssh
from $ scp
in ~/.ssh/rc
(to launch neofetch
only when I ssh
into the server, not when I scp
into it) ?
Note : I don't want to launch neofetch each time I launch bash, nor each time I launch a login shell, so putting it in /etc/bash.bashrc
or in /etc/profile
is not an option. I only want to launch it after an SSH connection.
I did some research and tried a few things :
Inspired by this post, I tried :
if [ -t 0 ]; then /usr/bin/neofetch; fi
and
if tty > /dev/null; then /usr/bin/neofetch; fi
But it's not working (
neofetch
is never launched, not even after an$ ssh
)Inspired by that post, I also tried to use the
$-
environment variable to distinguish between interactive and non interactive sessions, but it doesn't work either, because~/.ssh/rc
is parsed by dash, not by bash (and$-
is a bash variable)
I found however a working solution (well, sort of...). It was inspired by this post :
On the server, in
~/.ssh/rc
, I put :if [ ! "$LC_SCP" = "yes" ]; then /usr/bin/neofetch; fi
On the client, I have to set an
LC_SCP
environment variable before the$ scp
:
$ export LC_SCP=yes
$ scp -o SendEnv=LC_SCP remote-host:/t<TAB><TAB>
(works, doesn't launch neofetch)
It works, but it's cumbersomee. Isn't there a better way to distinguish between ssh
and scp
sessions in ~/.ssh/rc
?