diff --git a/config/git_template/hooks/ctags b/config/git_template/hooks/ctags new file mode 100755 index 0000000..17f802c --- /dev/null +++ b/config/git_template/hooks/ctags @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# inspired by https://tbaggery.com/2011/08/08/effortless-ctags-with-git.html +set -o errexit + +main() { + local git_dir + git_dir="$(git rev-parse --git-dir)" + + local tmp_tags + tmp_tags="$(mktemp)" + + trap 'rm -f "${tmp_tags}"' EXIT + + git ls-files | + ctags \ + --tag-relative \ + -L - \ + -f"${tmp_tags}" \ + --languages=-javascript,sql + + mv "${tmp_tags}" "${git_dir}/tags" +} + +main "${@}" diff --git a/config/git_template/hooks/post-checkout b/config/git_template/hooks/post-checkout new file mode 100755 index 0000000..f2a5b32 --- /dev/null +++ b/config/git_template/hooks/post-checkout @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -o errexit + +main() { + if [[ -x .git/hooks/ctags ]]; then + .git/hooks/ctags &>/dev/null & + fi +} + +main "${@}" diff --git a/config/git_template/hooks/post-commit b/config/git_template/hooks/post-commit new file mode 100755 index 0000000..f2a5b32 --- /dev/null +++ b/config/git_template/hooks/post-commit @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -o errexit + +main() { + if [[ -x .git/hooks/ctags ]]; then + .git/hooks/ctags &>/dev/null & + fi +} + +main "${@}" diff --git a/config/git_template/hooks/post-merge b/config/git_template/hooks/post-merge new file mode 100755 index 0000000..f2a5b32 --- /dev/null +++ b/config/git_template/hooks/post-merge @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -o errexit + +main() { + if [[ -x .git/hooks/ctags ]]; then + .git/hooks/ctags &>/dev/null & + fi +} + +main "${@}" diff --git a/config/git_template/hooks/post-rewrite b/config/git_template/hooks/post-rewrite new file mode 100755 index 0000000..c7c4071 --- /dev/null +++ b/config/git_template/hooks/post-rewrite @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -o errexit + +main() { + if [[ "${1}" == rebase && -x .git/hooks/ctags ]]; then + .git/hooks/ctags &>/dev/null & + fi +} + +main "${@}" diff --git a/gitconfig b/gitconfig index b413b06..04e46e6 100644 --- a/gitconfig +++ b/gitconfig @@ -65,3 +65,6 @@ [gpg] program = gpg2 + +[init] + templatedir = ~/.config/git_template