Last active
December 14, 2015 12:49
-
-
Save rbsgn/5089314 to your computer and use it in GitHub Desktop.
Shell script to open Xcode workspace or project from terminal.
This file contains 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
#!/bin/bash | |
find_project_or_workspace() { | |
MASK=$1 | |
ALL_PROJECTS_OR_WORKSPACES=`/bin/ls -1 -d $MASK 2>/dev/null` | |
FILE_TO_OPEN='' | |
if [ z"${ALL_PROJECTS_OR_WORKSPACES}" != z ] ; then | |
for i in ${ALL_PROJECTS_OR_WORKSPACES} ; do | |
if [ z"${PROJECT}" == z ] ; then | |
PROJECT_OR_WORKSPACE=${i} | |
else | |
break | |
fi | |
done | |
if [ z"${PROJECT_OR_WORKSPACE}" != z ] ; then | |
FILE_TO_OPEN=`basename "${PROJECT_OR_WORKSPACE}"` | |
fi | |
fi | |
echo $FILE_TO_OPEN | |
} | |
find_project() { | |
echo $(find_project_or_workspace '*.xcodeproj') | |
} | |
find_workspace() { | |
echo $(find_project_or_workspace '*.xcworkspace') | |
} | |
THING_TO_OPEN=$(find_workspace) | |
if [ z"${THING_TO_OPEN}" == z ]; then | |
THING_TO_OPEN=$(find_project) | |
fi | |
if [ z"${THING_TO_OPEN}" == z ]; then | |
echo "Can't find single workspace or project file in current directory, exiting..." | |
exit 1 | |
fi | |
open "${THING_TO_OPEN}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment