2012-05-03 10 views
10

पर काम नहीं करता है मेरे पास एक स्क्रिप्ट है (स्वयं द्वारा लिखी नहीं गई) जो मेरे कमांड प्रॉम्प्ट में गिट शाखा/svn शाखा दिखाती है। क्या किसी को पता है कि यह मैक पर क्यों काम नहीं करेगा? यह लिनक्स में पूरी तरह से काम करता है।PS1 env वैरिएबल मैक

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\]\[email protected]\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='\[email protected]\h:\w$(__repo)\$ ' 
fi 
unset color_prompt 

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

@ एलेन, मैं एक अंग पर बाहर जा रहा हूं और सुझाव देता हूं कि "मैं इसे मैक पर कैसे काम कर सकता हूं?" – blahdiblah

+0

@blahdiblah हम्म, संपादक सुझाव देते हैं कि यह "मैक पर यह क्यों काम नहीं करता है?" – Alain

+0

@ एलन डॉन! मैंने बस कर ही दिया था! – blahdiblah

उत्तर

21

Git के मैक ओएस एक्स प्रतिष्ठानों __git_ps1 शामिल नहीं है।

उपयोग:

alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'" 
एक प्रतिस्थापन के रूप में

+4

'\ (*। *)/'Grep के लिए hooray' \ (*। *)/' – Alain

+0

कोई सुंदर समाधान नहीं है, लेकिन मुझे थोड़ी देर पहले एक ही समस्या थी और यही वह है जो मैंने पाया और मेरे' प्रोफाइल ' '। शायद मैं एक बेहतर पाने में सक्षम नहीं था। मुझे यह देखकर खुशी होगी। –

+0

बहुत बहुत धन्यवाद, यह काम करता है! –

14

आपके द्वारा प्रदत्त स्क्रिप्ट __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 

  • यह समाधान भी Git के लिए टैब पूरा होने के लिए सक्षम बनाता है।
  • Mac OS X installations of git में __git_ps1 शामिल है, धन्यवाद gs-complet.bash का उल्लेख करने के लिए sschuberth और cheapener धन्यवाद।
+2

मेरी फ़ाइल /Aplplications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash में स्थित थी।एक्सकोड सीएलआई के साथ माउंटेन शेर स्थापित। –

1

आप macports (Git कोर) के माध्यम से Git स्थापित हैं, तो आप ~/.bash_profile के लिए निम्न जोड़ना चाहिए:

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

git-prompt.sh के स्थान कई बार बदल दिया है लग रहा था।

10

पर एक नया Yosemite मैक Git में बनाया का उपयोग कर, मैं इस प्रयोग किया है:

source /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash 
source /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh 
export PS1='\[\e]0;\[email protected]\h: \w\a\]\[\e[32;1m\]\[email protected]\h:\w \[\e[33;1m\]$(__git_ps1 "[%s] ")\[\e[32;1m\]\$ \[\e[0m\]' 

नोट: एल कैप्टन पर, मैं /Applications/Xcode.app/Contents/Developer/usr/share/git-core को Git लिपियों के पथ बदलना पड़ा और मैं आपके पास करने के लिए लगता है काम करने के लिए XCode स्थापित किया गया।

+0

दरअसल, यह ओएस एक्स 10.10 योसमेट पर काम करता है। –

+0

हाँ एसआईआर, पूरी तरह से काम किया। – oldergod

संबंधित मुद्दे