0

No matter what directory I enter, the terminal always shows me the root directory which is "Nidas-MBP"

Nidas-MBP% cd Projects
Nidas-MBP% ls
09-Selector-Exercise-Starter.zip    My Little Form
09_Selector_Exercise_Starter        Prefix Free File
Blog                                Recursion Practice
Callbacks                           Themes
Callbacks-Exercise                  Todo-Vanilla
Copywriting                         css3-contact-form.zip
Freelancer Theme                    webpack-deepdive
Frog Chase

Nidas-MBP% cd webpack-deepdive
Nidas-MBP% ls
es6-todomvc
Nidas-MBP% 

I have tried adding the following command to end of the ~/.bashrc file and the ~/.profile file but the terminal still remained unchanged.

PS1='[\u \W$] '

When I run echo "$PS1" it says

%m%#

I found two lines PS1=[ \W]\$ PS1='[ \W]$ ' inside ~/.bash_profile, so I replaced them both with PS1='[\u \W$] ' and typed source ~/.bash_profile. In response, my terminal started saying [\u \W$] instead of Nidas-MBP.

I have no idea what I should do now to bring it back to the way it used to be.

  • I cannot reproduce Darwin Kernel Version 17.4.0. Have you sourced the .bashrc and .profile files after making the changes? and/or restarted your terminal? – Jesse_b Aug 16 '18 at 16:51
  • @Jesse_b I am not sure what you mean by "sourced the files" but yes I did quit and restart my terminal after the change in the files. – rgb_jewel Aug 16 '18 at 16:59
  • 1
    What is the current value of $PS1? – RalfFriedl Aug 16 '18 at 17:02
  • @RalfFriedl How do I check that? – rgb_jewel Aug 16 '18 at 17:04
  • 2
    That's not the root directory. The root directory is named /. (It's not a directory at all, in fact. And you are not using the Bourne Again shell.) – JdeBP Aug 16 '18 at 17:36
1

Completely reworked per JdeBP's observation, this is zsh not bash.

bash and zsh are two different shells, and use two different sets of files when you start them. bash uses .bash_profile, .bashrc, and .profile. zsh uses .zprofile, .zshrc, and others.

zsh also uses different syntax for dictating the prompt. echo $PROMPT will tell you the prompt's current setting. To display, e.g., your current directory at the prompt, add this to $ZDOTDIR/.zshrc (if ZDOTDIR is not set, zsh will use HOME instead):

PROMPT='%~> '
Source

Then either source ~/.zshrc or restart the terminal.

  • You were right. I found two lines PS1=[ \W]\$ PS1='[ \W]$ ' inside ~/.bash_profile, so I replaced them both with PS1='[\u \W$] ' and typed source ~/.bash_profile. Now my terminal says [\u \W$] instead of Nidas-MBP – rgb_jewel Aug 16 '18 at 17:36
  • 1
    Psst! M. Kruse! There is a subtle clue, buried in a question comment made by the questioner, that the questioner has mis-labelled the question and is in fact using the Z shell. – JdeBP Aug 16 '18 at 17:43
  • @JdeBP I see it now, according to Google the default prompt for zsh is %m%#. Being unfamiliar with zsh, I didn't catch that. – Kevin Kruse Aug 16 '18 at 17:51
0

Obviously there must be something that changes PS1 after you set it.

To find where you can

  • Use grep in your home directory and in /etc.

    grep PS1 -r /etc $HOME
    
  • Use set -x after you set PS1 to see where it is changed.

  • Use strace to find out which file contains that value.
  • After I change the ~/.profile file and add the line PS1='[\u \W$] ' to the end of the file. Typing echo "PS1" to the terminal returns PS1. – rgb_jewel Aug 16 '18 at 17:14
  • You should not echo "PS1", but "$PS1". And just changing the file will have no effect, you need to login again. An alternative is source .profile, but then you don't know whether it will work on login. – RalfFriedl Aug 16 '18 at 17:17
  • Okay I've tried logging out and back in after changing the ~/.profile file but I still have the same problem. The root stills says Nidas-MBP no matter what. Typing grep in the command line showed me usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]] [-e pattern] [-f file] [--binary-files=value] [--color=when] [--context[=num]] [--directories=action] [--label] [--line-buffered] [--null] [pattern] [file ...] Also using echo "$PS1" returned %m%# after logging back in. – rgb_jewel Aug 16 '18 at 17:27
  • I added the command for grep. – RalfFriedl Aug 16 '18 at 17:35
0

I had no idea there was a difference in commands between bash and zsh. Apparently, I was supposed to type PS1='%m %1d$ ' instead. So I did that inside the ~/.zshrc file and it works now.

https://superuser.com/questions/1108413/zsh-prompt-with-current-working-directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.