Open Github/Bitbucket Page From Command Line
Here's little script that'll open a git repository's Github or Bitbucket page from the command line. Just add it to your path as an executable and use it from within a repo.
#!/usr/bin/env ruby
remote = begin `git config --get remote.origin.url` rescue nil end
if remote && remote != ""
remote.gsub!("\n", "")
if remote.include?("http")
remote.gsub!(".git", "")
system("open #{remote}")
else
host = /(?<=\@)(.*?)(?=\:)/.match(remote)[0]
user = /(?<=\:)(.*?)(?=\/)/.match(remote)[0]
repo = /(?<=\/)(.*?)(?=\.git)/.match(remote)[0]
url = "https://#{host}/#{user}/#{repo}"
system("open #{url}")
end
else
puts "not a git repo..."
end
Note, it'll only work on Mac OS X due to the open command. There's probably an equivalent for other operating systems.
Written by Philip Cunningham
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#