summaryrefslogtreecommitdiffstats
path: root/bash
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-10 17:53:22 +0100
committerDavid Robillard <d@drobilla.net>2020-11-10 17:53:22 +0100
commit1ba0741a3f55d66d20aadef274ed419d40654eaf (patch)
tree4007ba39825f93e3e83ea75f37f442540bff225a /bash
parentc243efbd725d97d0f0584a0217626bfe103c41bb (diff)
downloaddotfiles-1ba0741a3f55d66d20aadef274ed419d40654eaf.tar.gz
dotfiles-1ba0741a3f55d66d20aadef274ed419d40654eaf.tar.bz2
dotfiles-1ba0741a3f55d66d20aadef274ed419d40654eaf.zip
Add fancy git bash prompt
Diffstat (limited to 'bash')
-rw-r--r--bash/.bashrc22
1 files changed, 21 insertions, 1 deletions
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\$ '