2014-05-02 20 views
0

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

问题是,当我ssh进入远程机器时,选项卡名称被改变以反映我SSH'd的机器的身份。这很好。但是,当我回到本地机器时,选项卡名称不会重置为“ssh”,也不会重置为默认选项卡名称(当我打开新选项卡时显示的内容 - 我甚至有定义的此定义版本在我的~/.zshrc)。

有没有一种方法可以在我通过终止SSH连接回到本地主机时重置标签名称?

技术细节:

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

~/.zshrc相关部分:

source ~/.zsh_functions 
tabn "[email protected]" 

~/.zsh_functions相关部分:

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

回答

2

有一对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 "[email protected]" 
    printf '\e[23;2t' > /dev/tty 
} 

与任何堆栈,这假定任何对端压入堆栈中弹出的f在ssh之前退出。

+0

不幸的是,这并没有让我终端标签的标题回来。有关我如何解决这个问题的任何想法? – inspectorG4dget