-
Notifications
You must be signed in to change notification settings - Fork 0
/
open-xcode-project.sh
executable file
·66 lines (57 loc) · 1.64 KB
/
open-xcode-project.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# Open a given directory in Xcode. This is intended primarily to allow an "Open in Xcode"
# custom action to be added to Sourcetree.
set -e
dir="$1"
if [ "$dir" = "" ]; then
echo "usage: open-xcode-project.sh <directory>"
exit 255
fi
if [ "$dir" = "." ]; then
dir=$(pwd)
fi
proj=$(basename "$dir")
fn=$(echo "$dir/$proj.xcodeproj" | sed "s/ /\\\\ /g")
if [ -d "$fn" ]; then
echo "Found exact match, opening $fn"
open "$fn"
exit 0
fi
count=$(find "$dir" -maxdepth 1 -name '*.xcworkspace' | wc -l)
if [ "$count" -eq 1 ]; then
fn=$(find "$dir" -maxdepth 1 -name '*.xcworkspace')
echo "Found exactly one workspace, opening $fn"
open "$fn"
exit 0
fi
count=$(find "$dir" -name '*.xcodeproj' | wc -l)
if [ "$count" -eq 1 ]; then
fn=$(find "$dir" -name '*.xcodeproj')
echo "Found exactly one project, opening $fn"
open "$fn"
exit 0
fi
if [ -f "$dir/Package.swift" ]; then
echo "Found a Swift package file, opening Package.swift"
open "$dir/Package.swift"
exit 0
fi
echo "No project found, opening everything"
cd "$dir"
files=$(find . -maxdepth 1 -type f -not -path '*/\.*' -not -name '*.png' -not -name '*~' \
| sort)
dirs=$(find . -maxdepth 1 -type d -not -path '*/\.*' -not -path '.' \
-not -name 'build' -not -name 'cmake-build-*' -not -name 'dist' \
-not -name '*.egg-info' -not -name '.logs' \
| sort)
if [ -d .github ]; then
dirs=".github $dirs"
fi
if [ -f .gitignore ]; then
files=".gitignore $files"
fi
echo "$files"
echo "$dirs"
# shellcheck disable=SC2086
# Justification: None of the listed alternatives work in this instance.
open -a Xcode $dirs $files