9

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

Joseph K.
  • 1,055
  • 3
  • 23
  • 46

7 Answers7

19

Within ~/.zshrc

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

DISABLE_AUTO_TITLE="true"
SilverNak
  • 3,283
  • 4
  • 28
  • 44
9

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"
}
bluenote10
  • 23,414
  • 14
  • 122
  • 178
3

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"
  • 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? – Joseph K. Oct 13 '17 at 03:14
  • this does not work if remotely connected to a machine – alper Jul 20 '20 at 23:13
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.

Jilles van Gurp
  • 7,927
  • 4
  • 38
  • 46
1

This works for me:

DISABLE_AUTO_TITLE="true"

case $TERM in xterm*)
    precmd () {print -Pn "\e]0;%~\a"}
    ;;
esac
Banane
  • 755
  • 9
  • 10
1

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
s_musarat
  • 36
  • 3
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.

Quinn Carver
  • 587
  • 7
  • 14