Skip to content

Instantly share code, notes, and snippets.

@mbernson
Last active December 5, 2024 09:53
Show Gist options
  • Save mbernson/1c5ad83fe404018129ddd1b9f75545e9 to your computer and use it in GitHub Desktop.
Save mbernson/1c5ad83fe404018129ddd1b9f75545e9 to your computer and use it in GitHub Desktop.
X - Opens the Xcode workspace/project or Swift package in your current working directory using Xcode.
#!/usr/bin/env ruby
XCODE_PATH = File.expand_path(File.join(`xcode-select -p`.chomp, '../..'))
def open_cmd(pattern)
files = Dir.glob(pattern)
`open -a "#{XCODE_PATH}" "#{files.first}"` and exit if files.count == 1
end
open_cmd '*.xcworkspace'
open_cmd '*.xcodeproj'
open_cmd '*.playground'
open_cmd 'ios/*.xcworkspace' # React Native folder structure
open_cmd '.' if File.exists?('Package.swift')
puts 'No Xcode workspaces, projects, playgrounds, or packages found.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment