.git_helpers/ctags

Mon, 07 Mar 2016 20:52:13 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Mon, 07 Mar 2016 20:52:13 -0500
changeset 268
74dee06ae10e
parent 187
84c6fa7ebc05
permissions
-rwxr-xr-x

one last tweak

#!/usr/bin/env ruby

# Meant for use as a git hook:
#   CTAGS_HOOK=1 .git/hooks/ctags &>/dev/null </dev/null &
# or an aliased cmd on demand:
#   git config alias.ctags '!.git/hooks/ctags'
# or disable when you wish:
#   CTAGS_SKIP=1 git rebase

exit if ENV['CTAGS_SKIP']

ctags  = "/opt/local/bin/ctags"
ctags  = 'ctags' if !File.exists?(ctags)

dir    = `git rev-parse --show-toplevel`.chomp

conf   = "#{dir}/.git/ctags.conf"
target = "#{dir}/.tags"
tmp    = "#{dir}/#{$$}.tags"

opts   = File.exists?(conf) ? "--options=#{conf}" : ''

sleep 5 if ENV['CTAGS_HOOK']

open( target, File::RDONLY|File::CREAT, 0644 ) do |f|
  if ENV['CTAGS_HOOK']
    exit unless f.flock( File::LOCK_EX|File::LOCK_NB )
    exit unless ( Time.now - f.mtime ) > 60
  end

  system( <<-CMD ) or exit $?.exitstatus
    git ls-files \
     | #{ctags} --tag-relative -L - -f"#{tmp}" #{opts} \
    && mv #{tmp} #{target}
  CMD
end


mercurial