我可以获得终端所有权吗? (或以其他方式恢复旧的)

发布于 2024-09-08 20:15:51 字数 124 浏览 13 评论 0原文

使用echo -e "\e]0;some title\007"可以轻松设置终端标题。几乎适用于所有终端程序。

我想要的是在某个程序启动时设置终端标题 - 并在程序完成时恢复旧的标题。这可能吗?

Setting terminal title is easy with echo -e "\e]0;some title\007". Works with pretty much every terminal program.

What I want is to set terminal title when some program starts - and restore old one when it finishes. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧时光的容颜 2024-09-15 20:15:51

在 xterm 上,终端控制序列 22 和 23 工作正常,如下

#!/bin/sh
/bin/echo -ne '\033[22;0t'  # Save title on stack
/bin/echo -ne "\033]0;$(date)\007"
sleep 1
/bin/echo -ne '\033[23;0t'  # Restore title from stack

所示Mac OS X Terminal.App 不支持这样的操作。

On xterm, the terminal control sequences 22 and 23 work fine, as in

#!/bin/sh
/bin/echo -ne '\033[22;0t'  # Save title on stack
/bin/echo -ne "\033]0;$(date)\007"
sleep 1
/bin/echo -ne '\033[23;0t'  # Restore title from stack

It looks like this isn't supported in the Mac OS X Terminal.App though.

埖埖迣鎅 2024-09-15 20:15:51

我的解决方案是在脚本过程中设置窗口标题,然后在完成后取消设置窗口标题。取消设置标题将恢复为原始值。具体来说,我做了以下事情:

# Set the terminal title
printf "\e]2;%s\a" "running my script"
# Do whatever processing is required.
...

# Restore terminal title
printf "\e]2;\a"

My solution was to set the window title during my script, then unset the window title when I completed. Unsetting the title reverted to the original value. Specifically, I did the following:

# Set the terminal title
printf "\e]2;%s\a" "running my script"
# Do whatever processing is required.
...

# Restore terminal title
printf "\e]2;\a"
梦里梦着梦中梦 2024-09-15 20:15:51

有一些终端程序支持它(xterm 有编译时选项,如 RWS 提到的),但大多数终端程序只是缺乏这样的功能,特别是 Terminal.app。

There are some terminal programs that supporting it (xterm has compile time options for that, as mentioned by RWS), but most terminal programs simply lack such feature, including in particular Terminal.app.

|煩躁 2024-09-15 20:15:51

是的,这确实是可能的。请参阅 xterm 参考手册(例如示例)并漫步其中。 xterm 甚至为此构建了一个堆栈,因此您不必手动存储标题。

Yes, that is possible indeed. See a xterm reference manual (like this for example) and wander your way through it. xterm even has a build in stack for this, so you don't have to store the title manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文