Skip to content

Instantly share code, notes, and snippets.

@dive dive/pxed.sh

Created Jul 19, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

dive commented Jul 21, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.