~/.bash_aliases
where I set PS1, and is included in ~/.bashrc
(the default settings)
# color PS1
PS1="\[\033[01;90m\]\D{%H:%M} \[\033[01;33m\]Ubuntu\[\033[00m\] \[\033[01;34m\]\w\[\033[01;35m\]$(__git_ps1) \[\033[01;36m\]\$\[\033[00m\] "
But when I start a terminal I get error __git_ps1: command not found
But when I run the function manual $ __git_ps1
in a git folder it does echo the current branch.
Also when I manually run
$ PS1="\[\033[01;90m\]\D{%H:%M} \[\033[01;33m\]Ubuntu\[\033[00m\] \[\033[01;34m\]\w\[\033[01;35m\]$(__git_ps1) \[\033[01;36m\]\$\[\033[00m\] "
the PS1 gets updated and __git_ps1
part does get added.
I did not install it myself. I only installed git.
sudo apt install -y git
(git version 2.19.1)
__git_ps1
is defined in /usr/lib/git-core/git-sh-prompt
(the file on github)
grep __git_ps1 ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login ~/.bash_aliases /etc/bash.bashrc /etc/profile /etc/profile.d/* /etc/environment 2>/dev/null
Only the .bash_aliases
file shows up.
A full grep of git-sh-promt only returns binary matches
sudo grep 'git-sh-prompt' -nr /
What is wrong here?
$(__git_ps1)
will be evaluated whenPS1
is set, not whenPS1
is used (i.e., when the prompt is printed).__git_ps1
does come with git, in particular with the file/usr/lib/git-core/git-sh-prompt
. See my answer to the related question script to show git branch in bash no longer works on ubuntu 18.04.command not found
only once, right? Not for every single prompt in the terminal? I'd guess the usage of__git_ps1
in the definition of$PS1
comes before the function gets defined (e.g. by sourcinggit-sh-prompt
or your file~/.local/git-completion.bash
(shown in an older version of your post)).