【问题标题】:Maintain Tab Name on Return from SSH从 SSH 返回时保持选项卡名称
【发布时间】:2014-06-19 09:21:49
【问题描述】:

我使用多个终端选项卡,我使用选项卡上的名称进行管理。因此,我有名为“python”、“workspace”等的选项卡。其中一个选项卡用于与远程计算机的 SSH 连接,名为“ssh”。

问题是,当我通过 SSH 连接到远程机器时,选项卡名称会更改以反映我通过 SSH 连接到的机器的身份。这很好。但是,当我回到本地计算机时,选项卡名称不会重置为“ssh”,也不会重置为默认选项卡名称(当我打开新选项卡时会出现什么 - 我什至有这个定义的自定义版本在我的~/.zshrc)。

当我通过终止 SSH 连接返回 localhost 时,是否可以重置选项卡名称?

技术细节:

  • 操作系统:Mac OS X 10.9.2
  • 外壳:zsh

~/.zshrc的相关部分:

source ~/.zsh_functions
tabn "ashwin@cortana"

~/.zsh_functions的相关部分:

function tabn {
  printf "\e]1;$1\a"
}

【问题讨论】:

    标签: macos shell ssh zsh


    【解决方案1】:

    有一对xterm escape sequences(大多数终端也可以识别)可以保存和恢复窗口标题。以下命令会将当前窗口标题压入堆栈:

    printf '\e[22;2t'
    

    这会恢复它:

    printf '\e[23;2t'
    

    您可以定义一个包装 ssh 的函数来自动保存当前标题并在 ssh 完成后恢复它:

    ssh () {
        # If you redirect the output of ssh to a file or a pipeline,
        # make sure these terminal sequences go to the terminal, not
        # standard output.
        printf '\e[22;2t' > /dev/tty
        command ssh "$@"
        printf '\e[23;2t' > /dev/tty
    }
    

    与任何堆栈一样,这假设在远程端的堆栈上推入的任何内容都在ssh 退出之前弹出。

    【讨论】:

    • 不幸的是,这并没有让我恢复终端标签的标题。关于如何解决这个问题的任何想法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多