|
1 #!/usr/bin/env ruby |
|
2 |
|
3 # Meant for use as a git hook: |
|
4 # CTAGS_HOOK=1 .git/hooks/ctags &>/dev/null </dev/null & |
|
5 # or an aliased cmd on demand: |
|
6 # git config alias.ctags '!.git/hooks/ctags' |
|
7 # or disable when you wish: |
|
8 # CTAGS_SKIP=1 git rebase |
|
9 |
|
10 exit if ENV['CTAGS_SKIP'] |
|
11 |
|
12 ctags = "/opt/local/bin/ctags" |
|
13 ctags = 'ctags' if !File.exists?(ctags) |
|
14 |
|
15 dir = `git rev-parse --show-toplevel`.chomp |
|
16 |
|
17 conf = "#{dir}/.git/ctags.conf" |
|
18 target = "#{dir}/.tags" |
|
19 tmp = "#{dir}/#{$$}.tags" |
|
20 |
|
21 opts = File.exists?(conf) ? "--options=#{conf}" : '' |
|
22 |
|
23 sleep 10 if ENV['CTAGS_HOOK'] |
|
24 |
|
25 open( target, File::RDONLY|File::CREAT, 0644 ) do |f| |
|
26 if ENV['CTAGS_HOOK'] |
|
27 exit unless f.flock( File::LOCK_EX|File::LOCK_NB ) |
|
28 exit unless ( Time.now - f.mtime ) > 60 |
|
29 end |
|
30 |
|
31 system( <<-CMD ) or exit $?.exitstatus |
|
32 git ls-files \ |
|
33 | #{ctags} --tag-relative -L - -f"#{tmp}" #{opts} \ |
|
34 && mv #{tmp} #{target} |
|
35 CMD |
|
36 end |
|
37 |
|
38 |
|
39 |