Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.bash_profile PS1 to show current directory folder and a $ MAC osx

Tags:

bash

In my .bash_profile I currently have

PS1="$ "

which in my terminal returns '$ '

I want to show the current folder as well.

if I run the command, pwd /Users/Me/Sites/

I would want my bash prompt to return 'Sites$'

Thanks for all your help.

like image 836
thedanotto Avatar asked Jan 25 '15 13:01

thedanotto


People also ask

How do I show the current directory in Mac terminal?

Use pwd to identify the current directory of your Terminal session. Use ls to list the files in the current directory of your Terminal session. Use cd and cd .. to change directories of your Terminal session. Use open . to open the current directory of your Terminal session in Finder.

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.

Where is bash_profile stored Mac?

bash_profile for Mac Users. There is a hidden file in your Mac's user directory named . bash_profile. This file is loaded before Terminal loads your shell environment and contains all the startup configuration and preferences for your command line interface.

Which of the following will set your bash prompt to include the current working directory?

Bash prompt can be set by setting the environment variable PS1 . Current directory can be displayed in 3 types: Full path.


Video Answer


2 Answers

Note that if you don't want brackets or colors surrounding the current directory, you can use the simpler:

export PS1="\W$ "
like image 77
Mark Shust at M.academy Avatar answered Oct 10 '22 10:10

Mark Shust at M.academy


try this:

PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]'
like image 44
Mikolaj Avatar answered Oct 10 '22 09:10

Mikolaj