How do I set the iTerm2 session title through escape codes?

我的未来我决定 提交于 2019-12-11 05:57:59

问题


The iTerm2 page on badges mentions that session.name can be changed with escape codes, but describes the method somewhat cryptically:

session.name

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.

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

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)

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.)


回答1:


iTerm OSC 1337 proprietary codes end with ^G (BEL, or ASCII 7). The documentation may be broken. Try adding one at the end.



来源:https://stackoverflow.com/questions/56069907/how-do-i-set-the-iterm2-session-title-through-escape-codes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!