add ctags helper and alias

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
parent 197
85a414f67356
child 199
ecaa41f32b07

add ctags helper and alias

.hg_helpers/ctags file | annotate | diff | comparison | revisions
.hgrc file | annotate | diff | comparison | revisions
new file mode 100755
--- /dev/null
+++ b/.hg_helpers/ctags
@@ -0,0 +1,39 @@
+#!/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    = `hg root`.chomp
+
+conf   = "#{dir}/.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
+    hg stat -Aqn \
+     | #{ctags} --tag-relative -L - -f"#{tmp}" #{opts} \
+    && mv #{tmp} #{target}
+  CMD
+end
+
+
+
--- a/.hgrc
+++ b/.hgrc
@@ -18,6 +18,7 @@ pager = LESS='FSRX' less
 
 [alias]
 fetch = pull --rebase
+ctags = !~/.hg_helpers/ctags
 
 [merge-tools]
 vimdiff.executable = vim

mercurial