I'm trying to change my command promt in terminal. I keep getting the error:
-bash: __git_ps1: command not found
I've tried it just by typing it into the terminal as is: __git_ps1
. I've also tried it out in the .bash_profile
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
export PS1='[\W]$(__git_ps1 "(%s)"): '
fi
As you might be able to see/tell, yes, I do have the auto-completion installed and it does work great!
I came across this question: " PS1 env variable does not work on mac " which gives the code
alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"
So I add it to my .bash_profile
hoping that it will change something. Well, it did. It just changed the error output.
Here's the .bash_profile
with the addition:
alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
export PS1='[\W]$(__git_ps1 "(%s)"): '
fi
And now here's the changed error output:
sed: (%s): No such file or directory
Note: I've also moved the alias below the source with no difference. I have git version 1.7.12.1
This should be a simple change. Can someone please help me?
Edit 10/13/12
No, I definitely do not want to define __git_ps1 myself but was just trying to see if it would be recognized by doing so. Yes, I have the .git-completion.bash
file installed. Here's how I got auto completion on my machine.
cd ~
curl -OL https://github.com/git/git/raw/master/contrib/completion/git-completion.bash
mv ~/git.completion.bash ~/.git-completion.bash
A ls -la
then lists the .git-completion.bash
file.
Edit 10/13/12 - Solved by Mark Longair (below)
The following code worked for me in the .bash_profile
while others did not...
if [ -f ~/.git-prompt.sh ]; then
source ~/.git-prompt.sh
export PS1='Geoff[\W]$(__git_ps1 "(%s)"): '
fi
this works in OS 10.8 in the .bash_profile
Following worked for me like a charm:
Run following in your Terminal:
Open/Create bash_profile:
Add following to the file:
Finally, source it using:
This will solve the problem of
bash: __git_ps1: command not found
.Also your prompt will change to "os ". To change "os" to something else, modify "os" string in export PS1 line.
At least with Xcode 6, you already have
git-completion.bash
. It's inside the Xcode app bundle.Just add this to your .bashrc:
Add the source file in to the .bash_profile
This one worked for me, and it has colored git output and an indicator in the prompt whether files have changed / been added, right baked into it:
Be sure to use the correct path! I used homebrew to install git, use
brew list git
to get the path to your current installation.Would be nice not to use a hard coded path, but don't know how to get the path to the current installation.
More infos here: http://en.newinstance.it/2010/05/23/git-autocompletion-and-enhanced-bash-prompt/
Solution for MacOS Sierra and git version 2.10.1 <2017-2-06>
Step 1: Install the Git
You can skip this step if you already installed the latest git.
Note: if you install with
Installation Verification:curl [option] https://...
option to download, you would have to make sure your system support SSL. So for new comer, to download from browser and install directly from git installer is much easier.which git
git --version
current version should be 2.10.1.Step 2: Add your git profile to your shell
nano ~/.bash_profile
ornano ~/.bashrc
Depends on where your modification is.source /usr/local/git/contrib/completion/git-completion.bash
source /usr/local/git/contrib/completion/git-prompt.sh
Note: git installation location changed from opt/ directory to usr/local/ after OSX upgrade to El Capitain, and this is why some of the old answer above doesn't work anymore in MacOS Sierra.
Add the following code to your PS1 configuration:
Option 1: add directly to your PS1:
I prefer this simple approach since I already know theexport PS1='\w$(__git_ps1 "(%s)") > '
.git-completion.bash
is there in my home directory, and I can add other prompt format in the front of it. here is my personal prompt for your reference:export PS1='\t H#\! \u:\w$(__git_ps1 "{%s}") -->> '
Option 2: Add a selection script
Save and use the profile:
source ~/.bash_profile
orsource ~/.bashrc