如何通过转义码设置iTerm2会话标题? [英] How do I set the iTerm2 session title through escape codes?
问题描述
徽章上的iTerm2页面提到可以使用转义码更改session.name,但对方法作了一些神秘的描述:
The iTerm2 page on badges mentions that session.name can be changed with escape codes, but describes the method somewhat cryptically:
session.name
session.name
当前会话的名称.默认为配置文件名称.可以通过转义序列 OSC 1进行更改;名称ST ,或在查看>编辑当前会话中编辑会话标题.
The current session's name. Defaults to the profile name. May be changed with the escape sequence OSC 1 ; name ST, or by editing the session title in View>Edit Current Session.
如果您在页面下方进一步浏览描述如何更改徽章的代码,我们会看到某种Rosetta商店:
If you look further down the page at code describing how to change badges, we see a sort of Rosetta Store:
徽章本身可以使用以下转义序列进行设置:
The badge itself may be set with the following escape sequence:
OSC 1337 ; SetBadgeFormat=Base-64 encoded badge format ST
这是在bash中工作的示例:
Here's an example that works in bash:
# Set badge to show the current session name and git branch, if any is set.
printf "\e]1337;SetBadgeFormat=%s\a" \
$(echo -n "\(session.name) \(user.gitBranch)" | base64)
我们可以由此推断出"OSC"代表"\ e]","ST"代表"\ a".但是即使有了这些信息,也无济于事:
We can infer from this that "OSC" is meant to stand in for "\e]" and "ST" for "\a". But even with that information, nothing works:
printf "\e]1;%s\a" "New Title"
echo -en "\e]1;New Title\a"
(如果您知道如何设置选项卡标题,那我也很感兴趣!但是我看不到任何迹象表明可以通过转义码来完成此操作.)
(If you know how to set the tab title, that's also of interest to me! But I don't see any indication that it's possible to do through escape codes.)
推荐答案
iTerm OSC 1337专有代码以^ G(BEL或ASCII 7)结尾.该文档可能已损坏.尝试在最后添加一个.
iTerm OSC 1337 proprietary codes end with ^G (BEL, or ASCII 7). The documentation may be broken. Try adding one at the end.
这篇关于如何通过转义码设置iTerm2会话标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!