3

I would like to remove the hostname (I think that's what it is?) which is printed after @ on each line of the zsh terminal.

At the moment at the start of every line I have:

name@names-MacBook-Pro ~ %

I would like it to be:

name ~ %

I tried making a file in the home directory called '.zshrc' and putting the following into it (based on ZSH: Hide computer name in terminal):

export DEFAULT_USER="$(whoami)"

but it hasn't changed anything. Does anyone have any advice?

6135105654
  • 202
  • 2
  • 5
  • 13

3 Answers3

5

I have found a solution. After reading this, I changed the zshrc file which is located in /etc/zshrc (to view hidden files in finder use CMD + Shift + .). Near the bottom of the zshrc file there is a section which is:

# Default prompt
PS1="%n@%m %1~ %# "

I changed this to:

# Default prompt
PS1="%n %1~ %# "

This had the effect which I was looking for.

6135105654
  • 202
  • 2
  • 5
  • 13
  • 1
    Note that you don't have to edit `/etc/zshrc` directly; you can override the value of `PS1` in your local `.zshrc` file instead. (If you have a single-user machine, it hardly matters, and if you are the administrator of a multi-user machine, it's certainly reasonable to edit `/etc/zshrc` to change the default prompt for all users.) – chepner Dec 14 '19 at 14:21
  • Mine said I didn't have access to file and I tried changing it from read only to read and write but it wouldn't allow me...why is this more complicated than it needs to be nobody wants it like that – Jordan Jul 22 '20 at 01:29
1
# Terminal prompt
DEFAULT_USER=$USER
prompt_dir() {
  prompt_segment blue $CURRENT_FG $DEFAULT_USER '%1~'
}

I have this in .zshrc :) You can use this and modify it to what you want :)

  • Thanks for posting. I've tried this, but it doesn't change the behaviour of my terminal. Are you running Catalina (I'm thinking maybe it's an issue with where it's looking for the .zshrc, like there was/is the issue with anaconda location)? – 6135105654 Dec 14 '19 at 12:09
0

To add here for one more customization of the prompt, I prefer the dollar sign ($) versus the ugly percent (%) symbol at the end of the prompt.

So a fairly bare prompt, I have:

PS1="%n$ "

Now my terminal just has (obviously replaced with whatever my username is with the $ at the end):

username$ 
firecape
  • 726
  • 6
  • 10