我希望根据ssh连接的HOSTNAME更改终端颜色。
我知道如何修改终端,但是如何使用ssh来添加钩子?
我可以使用shell函数包装ssh命令,或者替换二进制文件,但是它被其他应用程序用作依赖项,我宁愿不这样做。
答案 0 :(得分:4)
连接到远程服务器时,您可以使用LocalCommand
的{{1}}功能:
OpenSSH
除了编写 LocalCommand
Specifies a command to execute on the local machine after successfully connecting to the server. The command string extends to the end of the line, and is executed
with the user's shell. The following escape character substitutions will be performed: ‘%d’ (local user's home directory), ‘%h’ (remote host name), ‘%l’ (local host
name), ‘%n’ (host name as provided on the command line), ‘%p’ (remote port), ‘%r’ (remote user name) or ‘%u’ (local user name).
The command is run synchronously and does not have access to the session of the ssh(1) that spawned it. It should not be used for interactive commands.
This directive is ignored unless PermitLocalCommand has been enabled.
包装器之外,在结束与远程服务器的连接时,可能没有简单的方法来执行命令。
答案 1 :(得分:0)
围绕SSH的包装也许是最好的选择,即使您对此打折也是如此。但是,几乎每个程序都可以让您指定它们使用的“ ssh”命令。
在我自己的情况下,我有一个“ r”命令来替换“ ssh”,该命令执行帐户查找(用户名和主机别名以及DNS扩展,而无需依赖“ DNS解析器域列表”,其他情况除外)。这些是我获得各种程序调用“ r”而不是“ ssh”的注意事项。
scp
No config or environment variables, you must use option "-Sr"
scp -Sr ...
rsync
set environment variable
RSYNC_RSH="r -x"
unison
In ".unison/default.prf"
sshcmd = r
sshargs = -q -x
cssh
In ".clusterssh/config"
ssh=r
ssh_args= -x -o ConnectTimeout=10
multixterm
Use multixterm -xc "r %n" hostname...
vim netrw (file explorer)
Have it use the "rsync" command (set above)...
vim rsync://hostname/
OR for vim scp://hostname/...
In ".vimrc" configuration, redefine scp command to use.
let g:netrw_list_cmd="r USEPORT HOSTNAME ls -Fa1"
let g:netrw_scp_cmd="scp -Sr -q"
我的'r'脚本会解码所有的SSH参数(我见过使用过的),甚至处理非常旧的“ rsync”命令,这些命令在主机名之后放置了更多选项! (是的,我已经使用了很长时间了)