返回首页 - Notes - 2016

Ruby 生成 tags 文件


生成脚本

#!/usr/bin/env ruby

dirs = {}
Dir.entries(__dir__ + '/gems').each do |dir|
  unless %w[ . .. ].include?(dir)
    dir.match(/^(.*?)-((\d.?)+.*?)$/) do |match|
      name, version = match[1], match[2]
      unless dirs[name]
        dirs[name] = version
      else
        dirs[name] = version if Gem::Version.new(version) > Gem::Version.new(dirs[name])
      end
    end
  end
end


cmd = 'ctags -R --languages=ruby'
dirs.each do |name, version|
  cmd << " ./gems/#{name}-#{version}"
end


system cmd

使用说明

Mac 为例

  1. 将上述代码保存到一个文件,命名为 make_tags
  2. chmod a+x make_tags
  3. mv make_tags /usr/local/lib/ruby/gems/2.3.0
  4. cd /usr/local/lib/ruby/gems/2.3.0
  5. ./make_tags
  6. Vim 配置文件里面加上一行:set tags+=/usr/local/lib/ruby/gems/2.3.0/tags

date:2016-09-02