-bash: __git_ps1: command not found

后端 未结 6 950
灰色年华
灰色年华 2020-12-02 10:42

I tried to install Ruby 2.0. My command line urped and now looks like the following:

-bash: __git_ps1: command not found
[11:58:28][whatever@whatever ~]$ 
         


        
6条回答
  •  隐瞒了意图╮
    2020-12-02 11:08

    BASH has a whole slew of ways of automatically setting your prompt to give you nice information. You set the prompt by setting the PS1 environment variable. For example, if I set PS1="$ " my prompt will look like this:

    $ 
    

    Not too informative. All I can tell is that the command line is prompting me.

    However, If I set PS1=\u@\h: \w$, my prompt will now look like this:

    david@vegibank:/usr/bin$ 
    

    That tells me how I'm logged in (the \u), the machine I'm onto (\h), and the directory I'm in (the \w). If I use git, it would be nice if the git branch I'm in is also part of my prompt.

    This is exactly what is going on with your .profile, your .bashrc file, your .bash_login or your .bash_profile script. Or, what some system admin did in /etc/profile.

    There are a couple things you can do. Either:

    • Download the missing __git_ps1 and make sure it's in your $PATH environment variable (which is set by a combination of the various initialization files mentioned above)
    • Change your PS1 environment variable in whatever initialization file is being executed (I believe it is probably .bash_profile.

    Just add this as the last line:

    PS1="\u@\h:\w\n$ "
    

    The added \n prints the dollar sign prompt on the line below like this:

    david@vegibank:/usr/bin
    $ 
    

    I like to do that because the prompt can get rather long and editing the command line gets tricky when the prompt is longer than 30 to 50 characters. Otherwise, it's pretty much the standard prompt that most users use. You can see more about setting BASH prompts in the man pages. (Search for the word Prompting on that page).

    If you find it a bit confusing, be glad you're not using Kornshell. I use Kornshell and to get the same prompt PS1=\u@\h:\w\n$ does, I set my prompt as:

    export PS1='$(print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")'
    

提交回复
热议问题