Snippets

Ben Buchanan BASH: git bling

Created by Ben Buchanan

File prompt.sh Added

  • Ignore whitespace
  • Hide word diff
+#!/bin/bash
+
+environment=`uname -s`
+if [[ "$environment" == *CYGWIN* ]]
+then
+
+    function parse_git_branch {
+      git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
+    }
+    export PS1='\e[1;30m\][\e[\e[1;30m\]\e[1;33m\] \u@\H \[\e[1;32m\]\w\[\e[0m\] $(parse_git_branch) (check status manually) \e[1;30m\]]\e[37m\]\n> '
+    echo "Cygwin prompt formatting loaded - note no git status or stash parsing (too damn slow)"
+fi
+
+if [[ "$environment" == *Darwin* ]]
+then
+    # mac version - git stash handled a little differently
+    function parse_git_dirty {
+      [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "(*)"
+    }
+    function parse_git_stash {
+      [[ $(git stash list 2> /dev/null | tail -n1) != "" ]] && echo "^"
+    }
+    function parse_git_branch {
+      git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
+    }
+    export PS1='\e[1;37m\][\e[\e[1;37m\]\e[1;33m\] \u@\H \[\e[1;32m\]\w\[\e[0m\]$(git branch &>/dev/null;if [ $? -eq 0 ];
+    then echo " \[\033[01;34m\]\e[1;37m$(parse_git_branch)$(parse_git_stash)"; fi) \e[1;37m\]] \e[37m\]\n\[$PROMPT\]> '
+    echo "Prompt formatting loaded"
+fi
  1. 1
  2. 2
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.