J'utilise ceci guide pour afficher le nom de la branche dans le terminal gnome (Ubuntu 15.10) lors de l'utilisation d'un référentiel git. Sur la base de ce qui précède, j'ai maintenant le texte ci-dessous dans mon fichier ~ / .bashrc:
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
...
# Add git branch if its present to PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/()/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[3[01;32m\]\[email protected]\h\[3[00m\]:\[3[01;34m\]\w\[3[01;31m\]$(parse_git_branch)\[3[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt
En conséquence, je reçois maintenant:
doncçafonctionne[email protected]ôtea-t-elleétésupprimée?Etjem'attendraisaussiàcequelenomdelabranchesoitcoloré.Avantcelaressemblaitàceci:
UPDATE:J'aimaintenantessayéceguideàlaplace:
l'ajoutant à .bashrc:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ ()/'
}
export PS1="\[email protected]\h \[3[32m\]\w\[3[33m\]\$(parse_git_branch)\[3[00m\] $ "
et cela fonctionne:
Remarquezdans.bashrcJ'aiaussiceci(pardéfaut):
#uncommentforacoloredprompt,iftheterminalhasthecapability;turned#offbydefaulttonotdistracttheuser:thefocusinaterminalwindow#shouldbeontheoutputofcommands,notontheprompt#force_color_prompt=yes
Jen'aipasencoretrouvélaraisonpourlaquellecetextraitdonnelerésultatcorrectetnonlaversionprécédente.Descommentairesàcesujet?
Voicilaversiondemon.bashrcsurlaquellel'anciensnippetestactivéetquinefonctionnepas: