.hg_helpers/ctags

Sun, 06 Sep 2015 16:00:49 -0400

author
Meredith Howard <mhoward@roomag.org>
date
Sun, 06 Sep 2015 16:00:49 -0400
changeset 198
a4b45bcb4ba9
permissions
-rwxr-xr-x

add ctags helper and alias

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

mercurial