Last active
December 9, 2022 02:34
-
-
Save johngraham262/6546595 to your computer and use it in GitHub Desktop.
A simple bash script that will open a `.xcworkspace` if it exists in the current directory, otherwise a `.xcodeproj` if it exists, otherwise nothing. It will print the name of the file that is being opened. When using Cocoapods with iOS apps, a second file is created with the `MyProject.xcworkspace` name, alongside the `MyProject.xcproject` file…
This file contains hidden or 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
# Add the following lines of code to your `~/.bash_profile`, | |
# and then run `source ~/.bash_profile` to be able to execute | |
# this from the command line. | |
openx() { | |
fileToOpen=''; | |
for file in `find . -maxdepth 1 -name *.xcworkspace`; do | |
fileToOpen=$file | |
done | |
if [ -n "$fileToOpen" ] | |
then | |
echo $fileToOpen | |
open $fileToOpen | |
else | |
for file in `find . -maxdepth 1 -name *.xcodeproj`; do | |
fileToOpen=$file | |
done | |
if [ -n "$fileToOpen" ] | |
then | |
echo $fileToOpen | |
open $fileToOpen | |
else | |
echo "No xcode files to open." | |
fi | |
fi | |
} | |
# Shorthand version of "openx", use "ox" instead. | |
ox() { | |
openx | |
} |
Nice idea but this doesn't support workspace or project files with spaces in the name unfortunately.
Thank you for this script !! 👍
Nice one.
you should probably change the for ... find
with:
find . -maxdepth 1 -name *.xcworkspace -print0 | while IFS= read -r -d '' file; do
respectively
find . -maxdepth 1 -name *. xcodeproj -print0 | while IFS= read -r -d '' file; do
in case your project/workspace filename contains whitespaces.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
alias ox=openx