Created
July 19, 2020 15:39
-
-
Save dive/aa5b6713216ba87c0a07ab73440078f4 to your computer and use it in GitHub Desktop.
Shell script to scan and open Xcode projects in the current directory
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
#!/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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Xcode invocation tool - xed article.