-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_tags
executable file
·45 lines (37 loc) · 1.25 KB
/
run_tags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/ruby
#-*-ruby-*-
# A script to run ctags on all .rb and .js files in a project. Can be run on
# the current dir, called from a git callback, or install itself as a
# git post-merge and post-commit callback.
CTAGS = "$BREW_HOME/bin/ctags"
HOOKS = %w{ post-merge post-commit post-checkout }
HOOKS_DIR = '.git/hooks'
def install
if !File.writable?(HOOKS_DIR)
$stderr.print "The install option [-i] can only be used within a git repo; exiting.\n"
exit 1
end
HOOKS.each { |hook| install_hook("#{HOOKS_DIR}/#{hook}") }
end
def run_tags(dir)
if File.executable?(CTAGS) and File.writable?(dir)
vendor_exclude = Dir.pwd =~ /vendor$/ ? '' : '-not -path \\*/vendor/\\*'
%x{find #{dir} \\( -name \\*.rb -o -name \\*.js \\) #{vendor_exclude}| #{CTAGS} -e -f #{dir}/tags -L - 2>>/dev/null}
else
$stderr.print "FAILED to write tags file to #{dir}\n"
end
end
def install_hook(hook)
if File.exists?(hook)
$stderr.print "A file already exists at #{hook}, and will NOT be replaced.\n"
return
end
print "Linking #{__FILE__} to #{hook}\n"
%x{ln -s #{__FILE__} #{hook}}
end
if ARGV.first == '-i'
install
else
# if GIT_DIR is set, we are being called from git
run_tags( ENV['GIT_DIR'] ? "#{ENV['GIT_DIR']}/.." : Dir.pwd )
end