How does this script for naming iTerm tabs work?

别等时光非礼了梦想. 提交于 2019-12-02 21:29:41

If you want to have an alias for changing the tab name, you can actually do it by defining a function in your .profile/.bashrc file like this:

function renametab () {
    echo -ne "\033]0;"$@"\007"
}

I was having your same problem - but I saw the tab name briefly flash before going to back to what it was: the shell and the cwd. Turns out I had an environment variable changing the tab name on every shell command, so this fixed it for me:

export PROMPT_COMMAND=''

Now: echo -e "\033];MY_NEW_TITLE\007"

..works just fine and persists.

rename_tab () {
    TEXT=$1
    export PROMPT_COMMAND='echo -ne "\033]0;${TEXT}\007"'
}

This is a function. You can add it to your ~/.bashrc (or something similar, like a ~/.bash_profile). To rename the tabs, you can then do this:

$ rename_tab 'NEW NAME HERE'

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