From 1ba0741a3f55d66d20aadef274ed419d40654eaf Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 10 Nov 2020 17:53:22 +0100 Subject: Add fancy git bash prompt --- bash/.bashrc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'bash') diff --git a/bash/.bashrc b/bash/.bashrc index be81c7f..9250685 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -25,11 +25,31 @@ if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi +git_color() { + branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) + status=$(git status --porcelain -b 2>/dev/null) + if [[ "$status" == "## ${branch}...origin/${branch}" ]]; then + echo -e "\033[0;32m" # green + else + echo -e "\033[0;31m" # red + fi +} + +git_branch() { + a=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) + if [ -n "$a" ]; then + echo " [$a]" + else + echo "" + fi +} + # set fancy prompt if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # color supported #PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[32m\]╭─ \u@\h \w ─╼\n╰╼ \$\[\033[00m\] " - PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[32m\]\u@\h \w\n\$\[\033[00m\] " + #PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[32m\]\u@\h \w\n\$\[\033[00m\] " + PS1="\[\e]0;\u@\h: \w\a\]\[\e]0;\u@\h: \w\a\]\[\033[32m\]\u@\h \w\[\$(git_color)\]\$(git_branch)\n\[\033[0;32m\]$\[\033[00m\] " else # no color PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -- cgit v1.2.1