Git kullanıyorum, şu satırı .bashrc
olarak değiştirdim, pwd
Git Repo'dur, geçerli checkedout dalını sormak için. Ben kullanıyorum İşletim Sistemi: yerine yukarıdaki hattının Kabuk isteminde git repo mevcut şube görüntülemek için bu çizgiyi kullanıyorumGit'in yüklenip yüklenmediğini nasıl kontrol edelim .bashrc
# Original PS1 Line
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
Ubuntu 32bit.
# 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\]\$ '
Sorun
Ben arkadaşlara verince dizinleri arasında gezinirken, Shell değişen dizinlerde git şube için komut kontrolleri gibi, hata__git_ps1: command not found
verir olduğunu. Git'in yüklü olup olmadığını nasıl kontrol edebilirim ve yalnızca git'i yüklüyse şube denetimini gerçekleştirir mi?
Düzenleme: ayckoster önerdiği gibi , ben aşağıdaki kod hatları ile 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
Şimdi Everytime ı git --version
ekrana outputted olsun terminali açın Git yüklü iken, ve Git kurulmadığında terminal açılırken şu hatayı alıyorum:
The program 'git' is currently not installed. You can install it by typing:
sudo apt-get install git
Bunu nasıl temizlerim? Teşekkürler.
Final Düzenleme:
Bu Sonunda geldi kod, which
kullanarak kabuk isteminde
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
Not "git eksik" Echo. - Örneğin, Mac'te git 2.3.2'de mevcut değildir. Ancak burada mevcuttur: https://github.com/git/git/blob/8976500cbbb13270398d3b3e07a17b8cc7bff43f/contrib/completion/git-prompt.sh –