Sander Marechal
Sander Marechal

Reputation: 23216

How to extend __git_ps1? I get "command not found"

__git_ps1 returns (unknown) instead of nothing when I am not in a git directory. That's a change I'm not too happy with. So I am trying to extend it to get the old behaviour back. So, I added this in my ~/.bashrc and made sure that /etc/bash_completion is sourced before it:

__git_silent_ps1() {
    local b='$(__git_ps1 " (%s)")'
    if ["$b" != " ((unknown))"]; then
        echo -n $b
    fi
}

But when I use __git_silent_ps1 in my prompt definition, I get:

-bash: [$(__git_ps1 " (%s)"): command not found

When I just use __git_ps1 in my prompt definition I don't get that error but it displays the branch. Any idea why I am getting the error and how I can fix it?

Upvotes: 0

Views: 2103

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798666

Just as one doesn't write rmsomefile.txt, one shouldn't write ["$b".

    if [ "$b" != " ((unknown))" ]; then

Upvotes: 3

Related Questions