मैं गिट का उपयोग कर रहा हूं, मैंने .bashrc
में निम्न पंक्ति को बदल दिया है, वर्तमान में चेकआउट शाखा को तुरंत दिखाने के लिए, pwd
एक गिट रेपो है। ऑपरेटिंग सिस्टम मैं उपयोग कर रहा हूँ है: उबंटू 32 बिटयह जांचने के लिए कि क्या गिट स्थापित है .bashrc
# Original PS1 Line
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
मैं सुरक्षा प्रॉम्प्ट में Git रेपो की वर्तमान शाखा प्रदर्शित करने के लिए इस लाइन का उपयोग कर रहा हूँ, के बजाय, ऊपर लाइन।
# PS1 Line to show current Git Branch in the Prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;32m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '
समस्या है जब मैं यह मित्रों को दे, शैल निर्देशिका के बीच नेविगेट जबकि, त्रुटि __git_ps1: command not found
देता है, बदलते निर्देशिकाओं पर Git शाखा के लिए स्क्रिप्ट चेकों के रूप में है। मैं कैसे जांचूं कि गिट स्थापित है या नहीं और शाखा जांच केवल तभी किया जाए जब गिट स्थापित हो?
संपादित करें: ayckoster ने सुझाव दिया है, मैं कोड की निम्न लाइनों के साथ cameup:
if [ "$color_prompt" = yes ]; then
git --version
GIT_IS_AVAILABLE=$?
if [ $GIT_IS_AVAILABLE -eq 0 ]; then
# PS1 Line to show current Git Branch in the Prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;32m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '
else
# Original PS1 Line
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
fi
else
PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w\$ '
fi
अब, हर मैं टर्मिनल मैं git --version
स्क्रीन करने के लिए outputted मिल खोलने के लिए, जबकि Git स्थापित किया गया है, और मैं निम्नलिखित त्रुटि है, जबकि टर्मिनल खोलने Git स्थापित हो जब नहीं:
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
मैं इस कैसे साफ़ करूं? धन्यवाद।
अंतिम संपादित करें:
इस कोड मैं अंत में के साथ आया था, अपने सुरक्षा प्रॉम्प्ट
if [ "$color_prompt" = yes ]; then
if git --version &>/dev/null; then
# PS1 Line to show current Git Branch in the Prompt
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;32m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '
else
# Original PS1 Line
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
fi
else
if git --version &>/dev/null; then
# PS1 Line to show current Git Branch in the Prompt
PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w $(__git_ps1 "(%s)")\$ '
else
# Original PS1 Line
PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w\$ '
fi
fi
ध्यान दें कि '__git_ps1' समारोह हमेशा उपलब्ध नहीं है। - उदाहरण के लिए मैक पर यह मेरे गिट 2.3.2 पर उपलब्ध नहीं है। हालांकि यह यहां उपलब्ध है: https://github.com/git/git/blob/8976500cbbb13270398d3b3e07a17b8cc7bff43f/contrib/completion/git-prompt.sh –