【问题标题】:Dynamic window title in Urxvt with Zsh?带有Zsh的Urxvt中的动态窗口标题?
【发布时间】:2014-01-10 17:43:51
【问题描述】:

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

例如,如果我正在运行journalctl,我希望journalctl 显示为窗口标题。目前窗口标题只显示urxvt,如果我不运行任何命令就可以了。

【问题讨论】:

    标签: terminal x11 zsh


    【解决方案1】:

    这可以通过 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
    

    【讨论】:

      【解决方案2】:

      可能是一个矫枉过正的解决方案,但安装 oh-my-zsh 并使用其默认配置会给我一个动态窗口标题。以如下截图为例:

      【讨论】:

      • 当然是矫枉过正。顺便说一句,它完全按照另一个答案所说的那样做;可以在lib/termsupport.zsh看到。
      猜你喜欢
      • 2012-11-18
      • 1970-01-01
      • 2017-12-23
      • 2012-01-06
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      • 2010-10-10
      • 2019-05-20
      相关资源
      最近更新 更多