如何在通过 ssh 连接到远程服务器时在 Fish shell 中自动启动 tmux

rom*_*inf 4 bash ssh autologin tmux fish

我从外壳切换bashfish外壳。我喜欢它并决定也在我的服务器上使用它。如何tmux在连接时自动启动ssh?我按照bash 的说明进行操作,但shellfish不同,如果不进行基本重写,这个方法就无法工作。

rom*_*inf 5

我重写了剧本。最棘手的部分是ssh通过退出来断开连接fish,因为exit内部./.config/fish/config.fish不起作用。

tmux仅当 的父级fish是时才开始ssh

这是我的./.config/fish/config.fish文件的一部分:

if status --is-login
    set PPID (echo (ps --pid %self -o ppid --no-headers) | xargs)
    if ps --pid $PPID | grep ssh
        tmux has-session -t remote; and tmux attach-session -t remote; or tmux new-session -s remote; and kill %self
        echo "tmux failed to start; using plain fish shell"
    end
end
Run Code Online (Sandbox Code Playgroud)

更可读的版本可以在我的另一个问题中找到(感谢fish shell的作者荒谬的鱼): How to use booleans in Fish shell?