Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the terminal prompt to just current directory? [closed]

I am using a Macbook Pro, and I wanted to change it to the current directory and a dollar sign prompt in Terminal. I've already looked at these resources to try and solve this issue.

I tried modifying the ~/.bashrc file and saving it but it did not seem to work.

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PS1="\W$ ”

The last line is what I added to change the prompt.

like image 462
Rishi Avatar asked Jan 03 '14 21:01

Rishi


People also ask

How do I get the current directory in Terminal Mac?

To do that you use the ls (or list) command. Type ls and press the Return key, and you'll see the folders (and/or files) in the current directory.

How do I show the current directory in bash?

By default, bash shows just your current directory, not the entire path. To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd. This tells you that you are in the user sam's directory, which is in the /home directory.

How do I get the current path in Linux terminal?

To print the current working directory, we use the pwd command in the Linux system. pwd (print working directory) – The pwd command is used to display the name of the current working directory in the Linux system using the terminal.


2 Answers

This should be done in .bash_profile, not .bashrc.

nano ~/.bash_profile

Add a line containing this:

export PS1="\W\$ "

.bashrc is ONLY excuted when starting a sub-shell. bash login shell uses the following initialization scripts:

.bash_profile
.bash_login
.profile
like image 196
l'L'l Avatar answered Nov 12 '22 12:11

l'L'l


You need to escape the dollar sign. Like this:

$ PS1="\W\$ "
~$ cd tmp
/Users/philip/tmp
tmp$

And once you change your .bashrc you either need to logout/back-in or . ~/.bashrc to re source it.

I would humbly recommend not doing this. Having a full path is very useful as 'tmp' directories could be anywhere. Consider using "\w" which does relative path (ie. uses ~ to represent HOME)

like image 42
Philip Hallstrom Avatar answered Nov 12 '22 11:11

Philip Hallstrom