Skip to content

Instantly share code, notes, and snippets.

@bryanl
Forked from tobias/run_tags.rb
Created April 2, 2009 16:49

Revisions

  1. bryanl revised this gist Apr 2, 2009. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion run_tags.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # git post-merge and post-commit callback.

    CTAGS = '/opt/local/bin/ctags'
    HOOKS = %w{ post-merge post-commit }
    HOOKS = %w{ post-merge post-commit post-checkout }
    HOOKS_DIR = '.git/hooks'

    def install
  2. @tobias tobias revised this gist Mar 28, 2009. 1 changed file with 42 additions and 42 deletions.
    84 changes: 42 additions & 42 deletions run_tags.rb
    Original file line number Diff line number Diff line change
    @@ -1,43 +1,43 @@
    #!/usr/bin/ruby
    #-*-ruby-*-
    # A script to run ctags on all .rb 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 = '/opt/local/bin/ctags'
    HOOKS = %w{ post-merge post-commit }
    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)
    %x{find #{dir} -name \*.rb | #{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 )
    #!/usr/bin/ruby
    #-*-ruby-*-
    # A script to run ctags on all .rb 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 = '/opt/local/bin/ctags'
    HOOKS = %w{ post-merge post-commit }
    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)
    %x{find #{dir} -name \\*.rb | #{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
  3. @tobias tobias renamed this gist Jan 1, 2009. 1 changed file with 15 additions and 12 deletions.
    27 changes: 15 additions & 12 deletions ruby_tags.rb → run_tags.rb
    Original file line number Diff line number Diff line change
    @@ -2,10 +2,10 @@
    #-*-ruby-*-
    # A script to run ctags on all .rb files in a project. Can be run on
    # the current dir, called from a git callback, or install itself as a
    # git post-merge callback.
    # git post-merge and post-commit callback.

    CTAGS = '/opt/local/bin/ctags'
    HOOK = 'post-merge'
    HOOKS = %w{ post-merge post-commit }
    HOOKS_DIR = '.git/hooks'

    def install
    @@ -14,27 +14,30 @@ def install
    exit 1
    end

    full_hook = "#{HOOKS_DIR}/#{HOOK}"
    if File.exists?(full_hook)
    $stderr.print "A file already exists at #{full_hook}; exiting.\n"
    exit 1
    end

    print "Linking #{__FILE__} to #{full_hook}\n"
    %x{ln -s #{__FILE__} #{full_hook}}
    HOOKS.each { |hook| install_hook("#{HOOKS_DIR}/#{hook}") }
    end

    def run_tags(dir)
    if File.executable?(CTAGS) and File.writable?(dir)
    %x{find #{dir} -name \*.rb | #{CTAGS} -e -f #{dir}/TAGS -L -}
    %x{find #{dir} -name \*.rb | #{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
    end
  4. @tobias tobias created this gist Jan 1, 2009.
    40 changes: 40 additions & 0 deletions ruby_tags.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/usr/bin/ruby
    #-*-ruby-*-
    # A script to run ctags on all .rb files in a project. Can be run on
    # the current dir, called from a git callback, or install itself as a
    # git post-merge callback.

    CTAGS = '/opt/local/bin/ctags'
    HOOK = 'post-merge'
    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

    full_hook = "#{HOOKS_DIR}/#{HOOK}"
    if File.exists?(full_hook)
    $stderr.print "A file already exists at #{full_hook}; exiting.\n"
    exit 1
    end

    print "Linking #{__FILE__} to #{full_hook}\n"
    %x{ln -s #{__FILE__} #{full_hook}}
    end

    def run_tags(dir)
    if File.executable?(CTAGS) and File.writable?(dir)
    %x{find #{dir} -name \*.rb | #{CTAGS} -e -f #{dir}/TAGS -L -}
    else
    $stderr.print "FAILED to write TAGS file to #{dir}\n"
    end
    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