Urxvt中的动态窗口标题与Zsh?

时间:2013-12-22 08:52:40

标签: terminal x11 zsh

如何在Zsh shell中将Urxvt的窗口标题设置为当前运行的(交互式)命令?

例如,如果我正在运行journalctl,我希望journalctl显示为窗口标题。目前,窗口标题只显示urxvt,如果我没有运行任何命令,这很好。

2 个答案:

答案 0 :(得分:10)

使用precmd和preexec挂钩可以实现这一点。我将它用于我的xterm。它可能没有修改。如果没有,调整的地方是设置终端标题的转义序列,这里是ESC,],0 ,;。

case $TERM in
  (*xterm* | rxvt)

    # Write some info to terminal title.
    # This is seen when the shell prompts for input.
    function precmd {
      print -Pn "\e]0;zsh%L %(1j,%j job%(2j|s|); ,)%~\a"
    }
    # Write command and args to terminal title.
    # This is seen while the shell waits for a command to complete.
    function preexec {
      printf "\033]0;%s\a" "$1"
    }

  ;;
esac

答案 1 :(得分:-2)

可能是一个过度使用的解决方案,但安装oh-my-zsh并使用其默认配置为我提供了一个动态窗口标题。请参阅以下屏幕截图作为示例:

enter image description here