Issue
I have found plenty of answers/packages for setting the tab title of a console window, e.g. href="https://stackoverflow.com/questions/29548477/how-do-you-set-the-terminal-tab-title-from-node-js">How do you set the terminal tab title from Node.js?
Is there a way to get the title of a tab? I want to set it when the app launches and reset it back to what it was when it exits.
const getTitle = () => 'TODO'
const title = getTitle()
// set title
process.stdout.write('\x1b]0;My App Title\x07')
process.on('exit', () => process.stdout.write(`\x1b]0;${title}\x07`))
If it's possible, my guess is I would need to temporarily pipe stdout to a memory stream, console.log
some voodoo, set title = myStream.toString()
, then redirect stdout to the original stream. I don't know what the voodoo would be, though.
I'm using Git Bash (inside Windows Terminal), and if there's no cross-platform way to do this (i.e. retrieving the title from command prompt, powershell, zsh, etc), I'm totally fine with that. I did find Linux how to get window title with just shell script? which is a shell script that does this, but it relies on pstree, which is not included in Git Bash. I suppose I could download Windows SysInternals and use pslist64.exe -t
in a child process, but that seems like a lot of work for something that is either natively impossible or natively simple--i.e. far more work and headache than it is worth.
Thoughts? Ideas? Hacks?
Solution
You are looking for process.title
. You can get and set the value to any string or number.
Answered By - aroary Answer Checked By - Mildred Charles (WPSolving Admin)