Can I get the name of the terminal? (or otherwise restore the old one)

Setting a terminal header is easy with echo -e "\e]0;some title\007". It works with almost all terminal programs.

I want to set the title of the terminal when some program starts, and restore the old one when it ends. Is it possible?

+3
source share
4 answers

There are some terminal programs that support it (xterm has compile-time options, as indicated by RWS), but most terminal programs simply lack such a function, including, in particular, Terminal.app.

+3
source

xterm 22 23 ,

#!/bin/sh
/bin/echo -ne '\033[22;0t'  # Save title on stack
/bin/echo -ne "\033]0;$(date)\007"
sleep 1
/bin/echo -ne '\033[23;0t'  # Restore title from stack

, Mac OS X Terminal.App.

+4

Yes it is possible. See the Reference Guide xterm(for example, this ) and go through it. xtermhas a built-in stack for this, so you do not need to save the header manually.

+1
source

My solution was to set the window title during my script and then disable the window title when I was done. Cancellation of the header returned to its original value. In particular, I did the following:

# Set the terminal title
printf "\e]2;%s\a" "running my script"
# Do whatever processing is required.
...

# Restore terminal title
printf "\e]2;\a"
0
source

Source: https://habr.com/ru/post/1754317/


All Articles