Permalink
Browse files

Introduces `git_template` for init templating

Inspired by http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html

* Make `ctags` executable configurable
* Adds `git ctags`
* Runs `ctag` on `commit` / `branch` / `checkout`
* Extensible via `~/.git_template.local/hooks/{pre,post}-*`
* explain `git_template` under `git` section
  • Loading branch information...
seanpdoyle committed Jul 18, 2014
1 parent 73497a7 commit cbdcbce01dea1ab3850be2311f33f00d75f6088b
View
@@ -159,6 +159,8 @@ configuration:
* Adds a `merge-branch` alias to merge feature branches into master.
* Adds an `up` alias to fetch and rebase `origin/master` into the feature
branch. Use `git up -i` for interactive rebases.
+* Adds `post-{checkout,commit,merge}` hooks to re-index your ctags.
+ To extend your `git` hooks, create executable scripts in `~/.git_template.local/hooks/post-{commit,checkout,merge}`
[Ruby](https://www.ruby-lang.org/en/) configuration:
View
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+set -e
+
+PATH="/usr/local/bin:$PATH"
+dir="`git rev-parse --git-dir`"
+trap 'rm -f "$dir/$$.tags"' EXIT
+git ls-files | \
+ "${CTAGS:-ctags}" --tag-relative -L - -f"$dir/$$.tags" --languages=-javascript,sql
+mv "$dir/$$.tags" "$dir/tags"
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+LOCAL_HOOK=$HOME/.git_template.local/hooks/post-checkout
+[[ -f $LOCAL_HOOK ]] && source $LOCAL_HOOK
+
+.git/hooks/ctags >/dev/null 2>&1 &
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+LOCAL_HOOK=$HOME/.git_template.local/hooks/post-commit
+[[ -f $LOCAL_HOOK ]] && source $LOCAL_HOOK
+
+.git/hooks/ctags >/dev/null 2>&1 &
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+LOCAL_HOOK=$HOME/.git_template.local/hooks/post-merge
+[[ -f $LOCAL_HOOK ]] && source $LOCAL_HOOK
+
+.git/hooks/ctags >/dev/null 2>&1 &
@@ -0,0 +1,4 @@
+#!/bin/sh
+case "$1" in
+ rebase) exec .git/hooks/post-merge ;;
+esac
View
@@ -1,3 +1,5 @@
+[init]
+ templatedir = ~/.git_template
[push]
default = current
[color]
@@ -10,6 +12,7 @@
co = checkout
co-pr = !sh -c 'git fetch origin pull/$1/head:pr/$1 && git checkout pr/$1' -
create-branch = !sh -c 'git push origin HEAD:refs/heads/$1 && git fetch origin && git branch --track $1 origin/$1 && cd . && git checkout $1' -
+ ctags = "!sh -c '[ -f .git/hooks/ctags ] || git init; .git/hooks/ctags' git-ctags"
delete-branch = !sh -c 'git push origin :refs/heads/$1 && git branch -D $1' -
merge-branch = !git checkout master && git merge @{-1}
pr = !hub pull-request

0 comments on commit cbdcbce

Please sign in to comment.