Skip to content

Instantly share code, notes, and snippets.

@cbowns cbowns/xcode.sh
Last active Dec 26, 2015

Embed
What would you like to do?
A shell function for opening an Xcode workspace or project in the current directory or in a directory passed as a parameter.To open Project.xcodeproj or Project.xcworkspace:`cd Project; xcode`. Alternately, `xcode Project/`.
# Base function:
# Takes two arguments: a directory and a name for Xcode.
function open_with_xcode {
targetDirectory=$1
xcodeApp=$2
# If there's a workspace file, open that.
didFindXCWorkspace=`find $targetDirectory -depth 1 | grep -i .xcworkspace | wc -l | sed -e 's/^ *//g' -e 's/ *$//g'`
# Testing a glob with -d, like
# if [ -d *.xcworkspace ];
# just yields errors when it doesn't.
# Stupid shell.
if [ $didFindXCWorkspace != 0 ]; then
open -a $xcodeApp $targetDirectory/*.xcworkspace([1])
return
fi
didFindXcodeproj=`find $targetDirectory -depth 1 | grep -i .xcodeproj | wc -l | sed -e 's/^ *//g' -e 's/ *$//g'`
if [ $didFindXcodeproj != 0 ]; then
open -a $xcodeApp $targetDirectory/*.xcodeproj([1])
return
fi
echo "No .xcworkspace or .xcodeproj found."
return 1
}
# Xcode shortcuts:
# Open things with Xcode.
function xcode {
xcodeAppName="Xcode"
targetDirectory=$1
if [ ! -n "$1" ]; then
# No argument, set it to cwd.
targetDirectory="."
fi
open_with_xcode $targetDirectory $xcodeAppName
}
function xcode_5 {
xcodeAppName="Xcode 5"
targetDirectory=$1
if [ ! -n "$1" ]; then
# No argument, set it to cwd.
targetDirectory="."
fi
open_with_xcode $targetDirectory $xcodeAppName
}
# For Xcode x.y betas:
function xcode_beta {
xcodeAppName=`ls /Applications/ | egrep "Xcode.-Beta." | sed 's-.app/--' | tail -1`
directory=$1
if [ ! -n "$1" ]; then
# No argument, set it to cwd.
directory="."
fi
open_with_xcode $directory $xcodeAppName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.