A nicer bash prompt I use includes a git completion script that indicates the branch of a repository I may be into. Like this:
Green indicates “master” is clean and no modified files are present. Red indicates there is something new in that branch.
In order to configure that, I had to include some instructions on my .bashrc file. It looks like this:
# git completion
PS1='\[\e[01;30m\]\t`if [ $? = 0 ]; then echo "\[\e[32m\] ✔ "; else echo "\[\e[31m\] ✘ "; fi`\[\e[00;40;37m\]\u\[\e[01;37m\]:`[[ $(git status 2> /dev/null | head -n2 | tail -n1) != "# Changes to be committed:" ]] && echo "\[\e[31m\]" || echo "\[\e[33m\]"[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] || echo "\[\e[32m\]"`$(__git_ps1 "(%s)\[\e[00m\]")\[\e[01;34m\]\w\[\e[00m\]\$ '
Now, sometimes (in a new environment mostly), we may configure the .bashrc just the way we want it and then:
Boom! You see a big
"__git_ps1: command not found" message.
That is because you don’t have the git-prompt.sh file you included in the directory loaded at the top of you .bashrc file (the
So in order to get rid of that, we need to include it. The file is available in
contrib/completion/git-prompt.bash from the git repository
So after you clone it, you should simply copy the missing files to your system file system. In my case, I preferred to copy the whole “completion” dir to my file systems, as I did not have it. So:
$ sudo cp -r completion/ /usr/share/git-core/contrib/
Now I have my git-completion.bash file in the correct place. Let’s see if that worked when running a new bash session:
Great! Worked like a charm.
Let me know if you have a different solution for it or if this did not solve your problem.
Thanks for reading.
Technically Speaking was used as a reference for this post.