How to change the terminal title
Asked Answered
L

8

14

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"?

Liew answered 13/10, 2017 at 2:53 Comment(0)
J
24

Within ~/.zshrc

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

DISABLE_AUTO_TITLE="true"
Journalese answered 12/11, 2017 at 8:18 Comment(1)
I had to Restart the terminal after making the change to make this workOfficious
E
13

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"
}
Electrodynamometer answered 7/1, 2020 at 9:58 Comment(0)
Q
4

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"
Quickfreeze answered 13/10, 2017 at 2:58 Comment(2)
That didn't do what I wanted. I tried on my mac's built in terminal with echo -n -e "\033]0;SERVER\007" and now it looks like username@devicename -- ~ -- -zsh. How do I reset it back? Also, is there more of a .zshrc type of approach?Liew
this does not work if remotely connected to a machineFaison
E
4

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
Estrous answered 13/4, 2023 at 8:31 Comment(0)
L
3

This works for me:

DISABLE_AUTO_TITLE="true"

case $TERM in xterm*)
    precmd () {print -Pn "\e]0;%~\a"}
    ;;
esac
Lantha answered 8/8, 2022 at 9:33 Comment(0)
H
2

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.

Hm answered 10/9, 2019 at 8:23 Comment(0)
A
0

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.

Alpenglow answered 16/2, 2022 at 14:54 Comment(0)
F
0

This builds on some of the other answers here, but provides a bit more of granular solution.

Rather than putting DISABLE_AUTO_TITLE="true" in your .zshrc file and making a blanket assumption that you always want to manually set the title for all terminals, you can alias the title command to only override your terminal title when you want to:

# ~/.zshrc

alias title='DISABLE_AUTO_TITLE="true"; title'

With this alias, you'll turn off the auto titling whenever you try to update the title of a terminal using the title command and it'll only apply to the terminal session in which you ran the title alias.

Falito answered 8/4, 2024 at 17:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.