# Pour que PS1 affiche la branche git: parse_git_branch() { # git branch sur le prompt (cf ligne de PS1 "prompt sans conditions") # sed sélectionne «*» en début de ligne et supprime l'espace avant le nom de branche git branch 2> /dev/null | sed -n -e '/^*/p' -e 's/* \(.*\)/*\1/' } git_branch=$(parse_git_branch) echo "DEBUG $git_branch" # Pour que la couleur soit différente si la branche n'est pas master: color_git_branch() { echo "DEBUG git_branch → $git_branch" if [[ "$git_branch" =~ master ]] ; # master then echo "DEBUG $git_branch ↔ branche master" echo -en "\[\e[44;37;1m\]" ; # blanc fond bleu color_branch='\[\e[44;37;1m\]' elif [[ ! "$git_branch" =~ master ]] ; # autre branche then echo "DEBUG $git_branch ↔ PAS LA BRANCHE MASTER" echo -en "\[\e[40;31;1m\]" ; # rouge color_branch='\[\e[40;31;1m\]' else : # pas de git = vide fi } # Factoriser lsb_release et contrôle: if [[ -f /usr/bin/lsb_release ]] ; then DebianRelease=$(lsb_release -cs) else # je n'installe pas d'autre distrib ni système. DebianRelease='Debian' fi echo "DEBUG color_prompt → $color_prompt" if [ "$color_prompt" = yes ]; then # avec git branch master: blanc sur bleu, autres: rouge sur noir PS1="${debian_chroot:+($debian_chroot)}\[\e[46;37;1m\]\u@\h:\[\e[43;36;1m\]\w\[\e[0m\]\n\[\e[46;33;1m\]$DebianRelease \t ${color_branch}${git_branch}\[\e[0m\]\$" else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\n$(lsb_release -cs)\t${git_branch}\$ ' fi # echo "DEBUG prompt sans condition de couleur! = annule les précédents" PS1='${debian_chroot:+($debian_chroot)}\[\e[46;37;1m\]\u@\h:\[\e[43;33;1m\]\w\[\e[0m\]\n\[\e[46;33;1m\]$DebianRelease \t \[\e[44;37;1m\]$(parse_git_branch)\[\e[0m\]\$' unset color_prompt force_color_prompt