Skip to content

Instantly share code, notes, and snippets.

@cyborch
Created March 6, 2018 15:42
Show Gist options
  • Save cyborch/dec84c38942277a34f5460d7b21c7dc4 to your computer and use it in GitHub Desktop.
Save cyborch/dec84c38942277a34f5460d7b21c7dc4 to your computer and use it in GitHub Desktop.
Open specified xcode project or workspace, or open a workspace or project in specified directory
# Open specified xcode project or worspace, or open a workspace or project in specified directory
xcode() {
dir=`pwd`
if [[ "$1" != "" ]] ; then
if [ ! -d $1 ] ; then
open -a Xcode $1
return
else
dir=$1
fi
fi
workspaces=( $(ls -d $dir/*.xcworkspace 2>/dev/null) )
projects=( $(ls -d $dir/*.xcodeproj 2>/dev/null) )
case ${#workspaces[@]} in
0)
case ${#projects[@]} in
0)
echo -e "\033[31mNo Xcode projects found in `dirname $dir`\033[39m"
sleep 100
return
;;
1)
open -a Xcode ${projects[0]}
return
;;
esac
;;
1)
open -a Xcode ${workspaces[0]}
return
;;
esac
echo -e "\033[31mMore than one project or workspace found:\033[39m"
echo ""
ls -d *.xcworkspace *.xcodeproj
echo ""
echo -e "\033[32mPlease specify one.\033[39m"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment