Question

I've set a bash prompt like this:

PS1='\W\[\e[31m\]$(git branch &>/dev/null; if [ $? -eq 0 ]; then \
  echo " $(git branch | grep '^*' |sed s/\*\ //)"; fi)'

I want to make it default in order not to enter it every time I open the terminal. (I'm using OSX lion / Terminal Version 2.2.1)


Solution: I put the PS1=... line in ~/.bash_profile as Hai Vu suggested.

Thank you all for your answers

Was it helpful?

Solution

Put the PS1=... line in ~/.bash_profile and it should work.

OTHER TIPS

In general, look also for /etc/profile, /etc/bashrc, ~/.sh_profile, or ~/.profile ( usually for root it's .profile, and for non-root .bash_profile ), etc. In various versions of bash and host platforms, successful hit may vary :) Theoretically, bashrc and bash_profile (shrc, sh_profile) are for different purpose, rc file for shell configuration, and profile for various settings not related to shell itself, they're processed in fixed order, including system-wide and per-user configuration.

And I'm not sure, if executing an external command like "git" and piping to sed, grep and more is wise to use with prompt setup.

Disclaimer: I know nothing about OSX...

As I stated in my comment, your ~/.bashrc file is the place to put the command.

Depending on how the the shell is invoked you might need to add the following lines to the file ~/.bash_login

if [ -f ~/.bash_login ]; then
    . .bashrc
fi

And again, don't do the sed-thingie yourself to get the git-branch name into your prompt. USe the amazing bash-script from here.

BTW, this is how my prompt looks like (using the script above):

PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h\[\e[31m\] $(__git_ps1 "%s") \[\e[0m\]\[\e[33m\]\w\[\e[0m\]\n\$ '
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top