Skip to content

Instantly share code, notes, and snippets.

@GoZOo
Last active October 12, 2017 09:32
Show Gist options
  • Save GoZOo/3736538 to your computer and use it in GitHub Desktop.
Save GoZOo/3736538 to your computer and use it in GitHub Desktop.
Couleur et branch dans le prompt Mac Fichier .bashrc
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-*color)
c_cyan=`tput setaf 6`
c_blue=`tput setaf 4`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
else
return 0
fi
echo -e " ($gitver)"
}
branch_color ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
color=""
if git diff --quiet 2>/dev/null >&2
then
color="${c_green}"
else
color=${c_red}
fi
else
return 0
fi
echo -ne $color
}
PS1='${debian_chroot:+($debian_chroot)}\[${c_green}\]\u@\h\[${c_sgr0}\]:\[${c_blue}\]\w\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]$ '
;;
*)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
;;
esac
# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
;;
*)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment