How to change the terminal title

24.7k Views Asked by At

I'm currently using Hyper terminal on a mac, but this question also applies to other types of terminals, e.g. iTerm

How do you change the terminal title from username@devicename:~ into just ~ or zsh.

Currently my shell is zsh with oh-my-zsh installed. I'm not looking for workarounds through powerline or themes.

One more question: How do you reset back after running echo -n -e "\033]0;SERVER\007"?

7

There are 7 best solutions below

2
Just a HK developer On

Have you googled to search for an answer? How about the following: https://alvinalexander.com/blog/post/mac-os-x/change-title-bar-of-mac-os-x-terminal-window

echo -n -e "\033]0;YOUR TITLE HERE\007"
1
Erik McDaniel On

Within ~/.zshrc

Uncomment the following line to disable auto-setting terminal title.

DISABLE_AUTO_TITLE="true"
0
Jilles van Gurp On

With iterm 2 3.3.3 there's a setting under preferences->profiles->general-basics->title that you can set to PWD (and a few other options). It seems they changed a few things related to this recently and this overrides whatever is in the .zshrc.

I'm guessing one of these options might turn of this behavior as well. In my case PWD is exactly what I want.

0
bluenote10 On

I'm using this in my .zshrc:

# oh-my-zsh seems to enable this by default, not desired for 
# workflow of controlling terminal title.
DISABLE_AUTO_TITLE="true"

function set_terminal_title() {
  echo -en "\e]2;$@\a"
}
0
Quinn Carver On

For Mac, first:

brew install wmctrl

then for Mac or Linux

wmctrl -r :ACTIVE: -N "~"

in the active window. Type man wmctrl if you want to say ways to select a window that is not active.

0
Banane On

This works for me:

DISABLE_AUTO_TITLE="true"

case $TERM in xterm*)
    precmd () {print -Pn "\e]0;%~\a"}
    ;;
esac
0
s_musarat On

If you can to set terminal name to "Terminal" instead of "username@devicename:~PWD" everytime you open a new zsh terminal you can do this:

nano ~/.zshrc

Uncomment (you can find the line by ctrl+W)

DISABLE_AUTO_TITLE="true"

Apply changes to your terminal by

source ~/.zshrc

If you want to set custom names to your terminals you can write this funcation at the end of ~./zshrc file and apply changes using source.

function stitle() {
  echo -en "\e]2;$@\a"
}

Can be used by:

source ~/.zshrc
stitle new title