git pull とかcheckoutで勝手にtags作成してほしかったので調べた時のをメモ。
プロジェクトのルートディレクトリ直下の.git/hooks
ディレクトリにhookさせるファイルを置けば良いんだけど毎回置くのも面倒なので勝手に作ってくれる設定
command
cd
mkdir -p .git_tmp/hooks
cd .git_tmp/hooks
touch post-commit # git commit hook
touch post-merge # git merge, git pull hook
touch post-checkout # git checkout hook
touch ctags
chmod +x *
post-
系、ctags
の中の記述は以下
post-系
#!/bin/sh
.git/hooks/ctags >/dev/null 2>&1 &
ctags
#!/bin/sh
/usr/local/bin/ctags -R .
git init
時に自動的に作成したhooksファイルが作成されるように以下を流す。
command
cd
git config --global init.templatedir '.git_tmp'
既存のgitプロジェクトにはgit init
コマンドを打てば設定したhooksが反映される。既にあるファイルは上書きされないみたいです。
vim-fugitiveを使っている場合
やらなくてもいいんだけど
vim-fugitiveはtagsの読み込み場所を追加してくれているようだ。
.git/tags
を閲覧できるようになっている。
https://github.com/tpope/vim-fugitive/blob/master/plugin/fugitive.vim#L154
tagsが普段見えないところに置ける。せっかくなのでそこに追加してあげる記述方法は以下。
ctags
#!/bin/sh
/usr/local/bin/ctags -R -f .git/tags `pwd`