Permalink
Browse files

add everything

  • Loading branch information...
1 parent 9ce3712 commit 364f3e873b32f11522a5c03781e3b4dea9451852 Thomas Vander Stichele committed Mar 29, 2012
Showing with 60 additions and 0 deletions.
  1. +7 −0 Makefile
  2. +19 −0 README
  3. +34 −0 git
View
@@ -0,0 +1,7 @@
+install:
+ @-mkdir -p $$HOME/bin
+ @-mkdir -p $$HOME/.bashrc.d
+ @ln -sf `pwd`/git $$HOME/.bashrc.d
+ @echo "to activate, make sure your .bashrc or .bash_profile has a line"
+ @echo "to source $$HOME/.bashrc.d/git"
+ @echo "and set the prompt with PS1=\"\\\$$(parse_git_branch)\$$PS1\""
View
@@ -0,0 +1,19 @@
+INSTALL
+-------
+
+- run 'make install' as a user to put bash scripts in place
+- make sure you source the script in your .bashrc or .bash_profile
+ source $HOME/.bashrc.d/git
+
+ (I have these lines in .bashrc to do so:
+
+if test -e ~/.bashrc.d
+then
+ for f in ~/.bashrc.d/*
+ do
+ source $f
+ done
+fi
+
+- set the prompt in your .bashrc or .bash_profile with
+ PS1="\$(parse_git_branch)$PS1"
View
@@ -0,0 +1,34 @@
+function is_submodule() {
+ local git_dir parent_git module_name path strip
+ # Find the root of this git repo, then check if its parent dir is also a repo
+ git_dir="$(git rev-parse --show-toplevel)"
+ parent_git="$(cd "$git_dir/.." && git rev-parse --show-toplevel 2> /dev/null)"
+
+ if [[ -n $parent_git ]]; then
+ strip=$((${#parent_git} + 1))
+ module_name=${git_dir:$strip}
+ # List all the submodule paths for the parent repo
+ while read path
+ do
+ if [[ "$path" != "$module_name" ]]; then continue; fi
+ if [[ -d "$parent_git/$path" ]]; then
+ echo $module_name
+ return 0;
+ fi
+ done < <(cd $parent_git && git submodule --quiet foreach 'echo $path' 2> /dev/null)
+ fi
+ return 1
+}
+
+function parse_git_branch {
+ ref=$(git symbolic-ref HEAD 2> /dev/null) || return
+ submodule=$(is_submodule)
+ if [[ $? -eq 0 ]]; then
+ SM="s:$submodule "
+ fi
+ DESC=" d:"$(git describe 2> /dev/null) || DESC=""
+ echo "("${SM}"b:"${ref#refs/heads/}${DESC}") "
+}
+
+# add to prompt by adding to .bashrc somewhere:
+# PS1="\$(parse_git_branch)$PS1"

0 comments on commit 364f3e8

Please sign in to comment.