Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/ruby
# MIT License: http://www.opensource.org/licenses/MIT
require 'pathname'
require 'open3'
# read arguments
shouldBuild = FALSE
initialDirectory = Pathname.getwd
# Using a path to differentiate between multiple versions of Xcode
pathToXcodeApp = "/Applications/Xcode.app"
for argument in ARGV
if argument.match(/-b/i) || argument.match(/--build/i)
shouldBuild = TRUE
# elsif argument.match(/-6/i)
# pathToXcodeApp = "/Applications/Xcode.app"
elsif argument.length
initialDirectory += argument
end
end
success = FALSE
initialDirectory.ascend do | directory |
directory.each_entry do | path |
if path.basename.fnmatch("*.xcworkspace")
system "open '#{directory + path}' -a '#{pathToXcodeApp}'"
success = TRUE;
end
end
if !success
directory.each_entry do | path |
if path.basename.fnmatch("*.xcodeproj")
if shouldBuild
stdin, stdout, stderr = Open3.popen3("xcodebuild -project '#{directory + path}' -scheme Debug")
log = stdout.read
if $?.exitstatus == 0
puts '** BUILD SUCCEDED **'
else
puts '** BUILD FAILED **'
puts log
end
else
system "open '#{directory + path}' -a '#{pathToXcodeApp}'"
end
success = TRUE;
end
end
end
end
if !success
print " Couldn't find an Xcode project or workspace for the '#{Pathname.getwd}' directory\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment