Last active
December 26, 2015 04:19
-
-
Save cbowns/7091798 to your computer and use it in GitHub Desktop.
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/`.
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
# 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