【问题标题】:Change title in redhat, bash在 redhat、bash 中更改标题
【发布时间】:2014-06-30 09:31:47
【问题描述】:

如何在 python 中更改“putty”标题?

在启用 python 时有效:

# python
>>> import sys
>>> sys.stdout.write("\x1b]2;Another Title\x07")

以下内容不起作用:

在py中:

# ./myscript

我的脚本:

#!/usr/bin/python
import sys
sys.stdout.write("\x1b]2;Another Title\x07")

回声

# echo "\x1b]2;Another Title\x07"
\x1b]2;Another Title\x07

回声-e

# echo -e "\x1b]2;Another Title\x07"

打印

# print
-bash: print: command not found

【问题讨论】:

  • 如果您指的是未扩展的十六进制代码,我认为这是因为 bash 默认扩展了八进制代码,请尝试\007。你能解释一下它是怎么不工作的吗?
  • 太棒了! ;) echo -e "\027Another Title\007"

标签: python bash putty


【解决方案1】:

谢谢,

解决方案: echo -e "\027另一个标题\007"

【讨论】:

    【解决方案2】:

    http://the.earth.li/~sgtatham/putty/0.63/htmldoc/Chapter4.html#config-title:

    PuTTY 允许服务器发送xterm 控制序列,在会话中修改窗口的标题。

    http://www.tldp.org/HOWTO/text/Xterm-Title:

    3.1。 xterm 转义序列

    窗口和图标标题可以在运行的xterm 中使用 XTerm 转义序列。以下序列在此有用 尊重:

    • ESC]0;stringBEL -- 设置图标名称和窗口标题为字符串
    • ESC]1;stringBEL -- 设置图标名称为字符串
    • ESC]2;stringBEL -- 设置窗口标题为字符串

      其中ESC 是转义字符(\033),BEL 是铃声 字符 (\007)。

    这意味着你想要的是:

    $ printf "\033]0;My shiny new title\007"
    

    PS:不要将echo 与选项一起使用(-n/-e,它不可移植)。

    【讨论】:

    • @flig 按照手册对我来说工作得非常好,既可以直接在 bash shell 中使用,也可以在 python shell 中使用 sys.stdout.write
    猜你喜欢
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-23
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    相关资源
    最近更新 更多