$GOPATH内のリポジトリを楽に移動する

必要なもの

こんな感じ

$ cat ~/.zshrc | grep anything-gorepo
alias gogo='cd $(anything-gorepo)'
#!/usr/bin/env ruby

# anything-gorepo

unless ENV['GOPATH']
  STDERR.puts '$GOPATH should not be empty'
  exit 1
end

require 'ruby-anything'

def directories path
  Dir.entries(path).select do |filename|
    File.directory?(File.join(path, filename))
  end.select do |filename|
    filename != '.' && filename != '..'
  end
end

gosrc = File.expand_path("#{ENV['GOPATH'].dup}/src")

repo_paths = []

directories(gosrc).each do |host|
  directories(File.join(gosrc, host)).each do |user|
    directories(File.join(gosrc, host, user)).each do |repo|
      repo_paths << File.join(host, user, repo) # diplay without gopath
    end
  end
end

STDOUT.puts File.join(gosrc, _anything_(repo_paths))

anything-gorepoは適当な名前でgem化するかも知れない。

追記

anything-gorepoはgemにした。