10

コマンドプロンプトでgitブランチ/ svnブランチを表示するスクリプト(自分で作成したものではない)があります。これがMacで機能しない理由を知っている人はいますか? Linuxで完全に動作します。

https://github.com/xumingming/dotfiles/blob/master/.ps1から:

# Display ps1 with colorful pwd and git status
# Acording to Jimmyxu .bashrc
# Modified by Ranmocy
# --

if type -P tput &>/dev/null && tput setaf 1 &>/dev/null; then
    color_prompt=yes
else
    color_prompt=
fi

__repo () {
    branch=$(type __git_ps1 &>/dev/null && __git_ps1 | sed -e "s/^ (//" -e "s/)$//")
    if [ "$branch" != "" ]; then
        vcs=git
    else
        branch=$(type -P hg &>/dev/null && hg branch 2>/dev/null)
        if [ "$branch" != "" ]; then
            vcs=hg
        elif [ -e .bzr ]; then
            vcs=bzr
        elif [ -e .svn ]; then
            vcs=svn
        else
            vcs=
        fi
    fi
    if [ "$vcs" != "" ]; then
        if [ "$branch" != "" ]; then
            repo=$vcs:$branch
        else
            repo=$vcs
        fi
        echo -n "($repo)"
    fi
    return 0
}

if [ "$color_prompt" = yes ]; then
# PS1='\[\e[01;32m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[33;40m\]$(__repo)\[\e[00m\]\$ '
    PS1='\[\e[01;32m\]\u\[\e[00m\]:\[\e[01;34m\]\W\[\e[33m\]$(__repo)\[\e[00m\]\$ '
else
    PS1='\u@\h:\w$(__repo)\$ '
fi
unset color_prompt

case "$TERM" in
xterm*|rxvt*)
  PS1="\[\e]0;\W\a\]$PS1"
  ;;
*)
  ;;
esac
4

4 に答える 4

21

Git の Mac OS X インストールには含まれていません__git_ps1

使用する:

alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"

代用として。

于 2012-05-03T16:10:30.737 に答える
14

コマンドが失敗した場合、指定したスクリプトはgitreposを検出__git_ps1できません。これをに追加し~/.bash_profileます:

source /usr/local/git/contrib/completion/git-completion.bash
source /usr/local/git/contrib/completion/git-prompt.sh

スクリプトファイルをとして保存したと仮定して~/.ps1、次も追加します。

source ~/.ps1

于 2012-07-10T02:09:10.060 に答える
1

macports (git-core) を介して git をインストールした場合は、以下を に追加する必要があります~/.bash_profile

source /opt/local/etc/profile.d/bash_completion.sh
source /opt/local/share/git-core/git-prompt.sh  

git-prompt.sh の場所が数回変更されたようです。

于 2013-04-02T13:27:26.053 に答える