I'm trying to make a CLI with cross-platform support using Python and whenever the user starts the CLI it changes the title of the terminal. In Windows, I would use title
but in Linux I don't know
By the way, I use WSL (Windows Subsystem for Linux) and I need in a Python app so it has to work with os.system()
I tried asking ChatGPT but it failed instead of changing the title of the window, it change it to this:
notmithun@HPE-BOOK840:~/scripts$ echo -ne '\\033]0;My new title\\007'
\033]0;My new title\007notmithun@HPE-BOOK840:~/scripts$
TL;DR:
What I want is to change the title of the Terminal window in Linux, similar to title
in CMD
I'm trying to make a CLI with cross-platform support using Python and whenever the user starts the CLI it changes the title of the terminal. In Windows, I would use title
but in Linux I don't know
By the way, I use WSL (Windows Subsystem for Linux) and I need in a Python app so it has to work with os.system()
I tried asking ChatGPT but it failed instead of changing the title of the window, it change it to this:
notmithun@HPE-BOOK840:~/scripts$ echo -ne '\\033]0;My new title\\007'
\033]0;My new title\007notmithun@HPE-BOOK840:~/scripts$
TL;DR:
What I want is to change the title of the Terminal window in Linux, similar to title
in CMD
1 Answer
Reset to default 1As @F.Hauri and @Cyrus suggested, you would need an another command running. Since, I am using a Python CLI, the title doesn't go away until it returns to it's shell.
In Python, you would do:
os.system("echo -en '\033]0;My new title\007'")
Or for more options,
print("\33]0;My new title\7")
The second option is more recommend.
Thank you @F.Hauri and @Cyrus for answering this!
echo -en '\033]0;My new title\007'
and maybesleep 2
to ensure having time to read effect:echo -en '\033]0;My new title\007'; sleep 2
– F. Hauri - Give Up GitHub Commented Jan 30 at 15:25echo -n $'\033]30;New Title\007'
. See: superuser/a/1580062/340330 – Cyrus Commented Jan 30 at 15:26