Created
March 7, 2013 00:52
-
-
Save jkubicek/5104617 to your computer and use it in GitHub Desktop.
Opens the currently active Xcode file in GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Get the current Xcode file | |
filename = `osascript -e 'tell application "Xcode" to set current_document_path to path of last source document'` | |
# Parse the file name | |
name = File.basename(filename) | |
dir = File.dirname filename | |
# Change to the working directory of our repo | |
Dir.chdir dir | |
root = `git rev-parse --show-toplevel`.strip | |
Dir.chdir root | |
# Get our relative path | |
rel_path = dir.sub(root, '') | |
# Fetch the current github URL | |
gurl = 'http://github.com/' + /(?<=\:)([^\.]+)/.match(`git config --get remote.origin.url`).to_s | |
# Fetch the current branch | |
branch = `git branch | grep "*" | sed "s/* //"`.strip | |
# Construct our URL | |
github_url = gurl + '/blob/' + branch + rel_path + '/' + name | |
# Open the URL | |
system("open #{github_url}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment