0

I'm trying to change my command prompt to display my current working directory, but it doesn't work for me. I have tried putting this in my bash_profile which is in my home directory:

PS1='\h:\w$ '

PS1='\h:$PWD \u$ '

and my prompt does change but it just shows the same as I'm putting in so it doesn't recognize things like \h and \w i think?

I'm running macOS Catalina 10.15.6enter image description here

1
2

You are using zsh so the definition needs to go to .zshrc and it's slightly different (see man zshmisc for all options). The equivalent for \h \w \$ in zsh is

PS1='%m %~%# '
  • %m The hostname up to the first '.'. An integer may follow the % to specify how many components of the hostname are desired. With a negative integer, trailing components of the hostname are shown.
  • %~ Current working directory. If an integer follows the %, it specifies a number of trailing components of the current working directory to show; zero means the whole path. If the current working directory starts with $HOME, that part is replaced by a ~
  • %# A # if the shell is running with privileges, a % if not.
9
  • I didn't notice I was using zsh to begin with so thanks for that. I have tried putting PS1='%m %~%# ' into a file called .zshrc in my home directory but it still won't work.. – Kippelicious Jul 27 '20 at 16:23
  • @kippelicious If you enter it directly at the prompt, does it work? – nohillside Jul 27 '20 at 16:26
  • no.. MacBook-Pro ~% is all i see.. – Kippelicious Jul 27 '20 at 16:30
  • @Kippelicious Unless I'm misunderstanding something, ~ is the shorthand for your user directory. ~/ refers to the same folder as /Users/yourusername/, and you can print your working directory at any point with pwd. Apologies if this is going above my head, and if what you're looking to have the full system path printed in place of the conventional user@ComputerName ~. I am unsure how to do that or why exactly you'd need to. Also, just ensuring you did touch ~/.zshrc after updating the file. – hdixon Jul 27 '20 at 17:11
  • @Kippelicious Looks about right, that's what you would get with \h \w \$ in bash: MacBook-Pro, is your hostname, ~ the current directory and % is the result of %# for a non-root user. What did you expect? – nohillside Jul 27 '20 at 17:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .