Skip to content

Instantly share code, notes, and snippets.

@dive
Created July 19, 2020 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dive/aa5b6713216ba87c0a07ab73440078f4 to your computer and use it in GitHub Desktop.
Save dive/aa5b6713216ba87c0a07ab73440078f4 to your computer and use it in GitHub Desktop.
Shell script to scan and open Xcode projects in the current directory
#!/usr/bin/env bash
set -euo pipefail
declare -a PROJECTS=()
function XcodeProjectsInCurrentDirectory() {
TEMP_FILE=$(mktemp)
SEARCH_PATTERN="*${1}*.xcodeproj"
find . -iname "$SEARCH_PATTERN" -type d -print0 | sort -z > "$TEMP_FILE"
while IFS= read -r -d $'\0'; do
PROJECTS+=("$REPLY")
done <"$TEMP_FILE"
rm -f "$TEMP_FILE"
}
function ListProjects() {
echo "Collecting .xcodeproj..."
XcodeProjectsInCurrentDirectory "$1"
if [ "${#PROJECTS[@]}" -eq 0 ]; then
echo "The project not found."
exit 0
elif [ "${#PROJECTS[@]}" -eq 1 ]; then
echo "Opening ${PROJECTS[0]}..."
xed "${PROJECTS[0]}"
else
echo "Please select a project:"
select d in "${PROJECTS[@]}"; do test -n "$d" && break; echo ">>> Invalid Selection"; done
echo "Opening ${d}..."
xed "$d"
fi
}
ListProjects "${1-}"
unset XcodeProjectsInCurrentDirectory;
unset ListProjects;
@dive
Copy link
Author

dive commented Jul 21, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment