最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

bash - Is there a `title` of Windows CMD in Linux - Stack Overflow

programmeradmin1浏览0评论

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

Share Improve this question edited Feb 1 at 10:28 Compo 38.7k5 gold badges31 silver badges45 bronze badges asked Jan 30 at 15:17 MithunMithun 194 bronze badges 9
  • drop one backslash and retry! – F. Hauri - Give Up GitHub Commented Jan 30 at 15:20
  • which backslash? – Mithun Commented Jan 30 at 15:23
  • on both pair: try: echo -en '\033]0;My new title\007' and maybe sleep 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:25
  • I suggest echo -n $'\033]30;New Title\007'. See: superuser/a/1580062/340330 – Cyrus Commented Jan 30 at 15:26
  • @F.Hauri-GiveUpGitHub so it didn't change anything at all ``` notmithun@HPE-BOOK840:~/scripts$ echo -en '\033]0;My new title\007' notmithun@HPE-BOOK840:~/scripts$ ``` – Mithun Commented Jan 30 at 15:27
 |  Show 4 more comments

1 Answer 1

Reset to default 1

As @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!

发布评论

评论列表(0)

  1. 暂无评论