Skip to content

Instantly share code, notes, and snippets.

@thefotes
Created February 23, 2020 19:28
Show Gist options
  • Save thefotes/0021479be7e55d713a50198a188b252f to your computer and use it in GitHub Desktop.
Save thefotes/0021479be7e55d713a50198a188b252f to your computer and use it in GitHub Desktop.
Opens either xcodeproj or xcworkspace in CWD
#!/bin/bash
set -e
xcodeproj=`find . -maxdepth 1 -name "*.xcodeproj"`
proj_name=`echo $xcodeproj | sed 's/.\///g' | sed 's/.xcodeproj//g'`
xcworkspace=`find . -maxdepth 1 -name "$proj_name.xcworkspace"`
if [[ ! -z $xcworkspace && -e $xcworkspace ]]; then
open $xcworkspace
else
open $xcodeproj
fi
@apexskier
Copy link

In case you haven't heard of it, there's a utility shipped with Xcode that does this and more called xed I just found out about. In my testing, it seems to handle opening single files, projects, workspaces (even when a project and workspace are in the same directory), playgrounds in the directory, and swift packages. (tested on xed version 11.4)

The only downside is that it's not very graceful when it can't find something to open.

@thefotes
Copy link
Author

thefotes commented Apr 3, 2020

My experience in used xed is that its slower, sometimes much slower, than using this script. Thats mainly anecdotal as I don't have pure quantitative data to back up the claim, but if I run them both xop is faster for me.

Id be interested in hearing whether or not you can reproduce this by using this script + xed on the same project.

@apexskier
Copy link

Thanks for the info, xed has been pretty fast for me. My big issue is that if it can't find something to open it gets slow, pops an alert within Xcode, and the exits cleanly (instead of exiting with an error code). I ended up rolling my own script as well.

@thefotes
Copy link
Author

thefotes commented Apr 4, 2020

Thanks for the info, xed has been pretty fast for me. My big issue is that if it can't find something to open it gets slow, pops an alert within Xcode, and the exits cleanly (instead of exiting with an error code). I ended up rolling my own script as well.

Right on 🤙

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment