1 #!/usr/bin/env ruby |
1 #!/usr/bin/env ruby |
2 |
|
3 # Meant for use as a git hook: |
|
4 # CTAGS_HOOK=1 ~/.git_helpers/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 # Create a tags file (target) using git's list of tracked files. If |
|
11 # .git/ctags.conf exists in the repo it is passed to the ctags invocation. |
|
12 # |
|
13 # When run w/o env, immediately run ctags and replace tags file. |
|
14 # |
|
15 # When run with CTAGS_HOOK, it's assumed to be a BG process and we want to wait |
|
16 # for git to be done applying changes no matter how the hook is triggered. |
|
17 # Wait five seconds, then bail if we can't get a lock on the tags file or if |
|
18 # it's been updated within the last minute. Only then, run ctags and replace |
|
19 # the tags file. |
|
20 |
|
21 exit if ENV['CTAGS_SKIP'] |
2 exit if ENV['CTAGS_SKIP'] |
|
3 ARGV.each { |o| exec('perldoc', $0) if o.match('help') } |
22 |
4 |
23 ctags = 'ctags' |
5 ctags = 'ctags' |
24 |
6 |
25 dir = `git rev-parse --show-toplevel`.chomp |
7 dir = `git rev-parse --show-toplevel`.chomp |
26 |
8 |
43 | #{ctags} --tag-relative -L - -f"#{tmp}" #{opts} \ |
25 | #{ctags} --tag-relative -L - -f"#{tmp}" #{opts} \ |
44 && mv #{tmp} #{target} |
26 && mv #{tmp} #{target} |
45 CMD |
27 CMD |
46 end |
28 end |
47 |
29 |
|
30 exit 0 |
48 |
31 |
|
32 <<'=cut' |
|
33 =head1 NAME |
49 |
34 |
|
35 git-ctags - run ctags on git tracked files |
|
36 |
|
37 =head1 SYNOPSIS |
|
38 |
|
39 git ctags |
|
40 |
|
41 echo 'CTAGS_HOOK=1 git ctags &' >> .git/hooks/post-checkout |
|
42 |
|
43 git checkout some/branch |
|
44 CTAGS_SKIP=1 git checkout some/branch |
|
45 |
|
46 =head1 DESCRIPTION |
|
47 |
|
48 Create a .tags file (target) using git's list of tracked files. If |
|
49 C<.git/ctags.conf> exists in the repo it is passed to the ctags invocation. |
|
50 |
|
51 When run w/o env, immediately run ctags and replace tags file. |
|
52 |
|
53 When run with C<CTAGS_HOOK>, it's assumed to be a BG process and we want to |
|
54 wait for git to be done applying changes no matter how the hook is triggered. |
|
55 Wait five seconds, then bail if we can't get a lock on the tags file or if it's |
|
56 been updated within the last minute. Only then, run ctags and replace the tags |
|
57 file. |
|
58 |
|
59 =cut |