Customizing the terminal prompt on Mac

Joined
Jul 9, 2008
Messages
8
Reaction score
0
Points
1
Iam using Mac OS X 10.5.2. Strangely, i dont have a .bashrc file on the users home folder. So i set out to create one. This is what i did.

First i created .bashrc by doing 'touch .bashrc'. Then i filled the following contents.

# User @ Host - working dir
#export PS1=”\u@\h\w$ ”
export PS1="\u@\h\w: "


In order to force Terminal.app to load .bashrc at the start: i opened terminal.app and then i opened preferences dialog. navigated to the startup section. Then i selected 'shells open with' under 'command(complete path)'. I gave the path as

/bin/bash –-rcfile /Users/pradeep/.bashrc --> pradeep is my username

Then i opened the new terminal window to check if it took effect, but there was no change.
am i doing something wrong ?

Best,
Pkri
 
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
I didn't have to do anything to my Terminal.app settings to get it to load .bashrc. Bash should do this automatically.

However, I believe that Terminal.app creates login shells. Hence, it will look for and process .bash_profile, not .bashrc. I have a one line .bash_profile in my home directory that just contains the line

Code:
source .bashrc
That does the trick for me.
 
T

tux08902

Guest
Terminal.app isn't as customizable as standard Unix terminals. You won't really be able to change colors and such as much as you would be able on say Xterm or Urxvt. You may want to just use Xterm through X.
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
Unless there's a lot of differences between Tiger and Leopard...
Bash will read a .bashrc just fine, assuming you've restarted Terminal.
There's no need to "force" it to read from preferences.
Terminal is very customizable, type "man bash" (without the quotes) in Terminal.
Goto http://www.dotfiles.com/ and look at/download some of the OS X files.
All kinds of ways to customize prompts and more.
My favorite is bash_styles.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
It'll also process .profile automatically.
 
OP
P
Joined
Jul 9, 2008
Messages
8
Reaction score
0
Points
1
But i don't find .bashrc, .bash_profile and .profile. When i tried loading them as nano .bashrc, i didnt get any tab completion. That's why i tried to create a .bashrc myself.
This is what i did now, i opened bash shell and then typed

bash --rcfile /Users/pradeep/.bashrc (or) bash -i

now the changes i mentioned in .bashrc works!! But when i open the new terminal the changes go away. I think this means it reads off /etc/bashrc first while starting up the machine or while opening a new terminal window, and not ~./bashrc. But ~./bashrc is invoked only when i do bash -i.
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
If you have a .bash_profile in your home dir, put this in it:
Code:
# include .bashrc if it exists

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi
That will make bash read your .bashrc in your home dir.
.bashrc is not in your home dir by default. You are supposed to create one to make changes to your $PATH or to make aliases, etc.
It needs to be plain text and executable as a linux file.
chmod +x .bashrc
will make it executable.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
there won't be any of them by default, you'll have to create them :)

Try doing a cp -p .bashrc .profile && . ./.profile
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top