6eb6017b3c08003e5885d0f8740e84c5417bc492
- Author
- Robby Russell <robby@planetargon.com>
- Committer
- Robby Russell <robby@planetargon.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/xcode/README.md b/plugins/xcode/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..15e65785905ff2c58024bb54229904f86432a561
4--- /dev/null
5+++ b/plugins/xcode/README.md
6@@ -0,0 +1,84 @@
7+# Xcode
8+
9+## Description
10+
11+This plugin provides a few utilities that can help you on your daily use of Xcode and iOS development.
12+
13+To start using it, add the `xcode` plugin to your `plugins` array in `~/.zshrc`:
14+
15+```zsh
16+plugins=(... xcode)
17+```
18+
19+
20+## Aliases
21+
22+| Alias | Description | Command |
23+|-------|------------------------------------------|------------------------------------------------|
24+| xcb | Build Xcode projects and workspaces | xcodebuild |
25+| xcdd | Purge all temporary build information | rm -rf ~/Library/Developer/Xcode/DerivedData/* |
26+| xcp | Show currently selected Xcode directory | xcode-select --print-path |
27+| xcsel | Select different Xcode directory by path | sudo xcode-select --switch |
28+
29+
30+
31+## Functions
32+
33+### `xc`
34+
35+Opens the current directory in Xcode as an Xcode project. This will open one of the `.xcworkspace` and `.xcodeproj` files that it can find in the current working directory.
36+Returns 1 if it didn't find any relevant files.
37+
38+### `simulator`
39+
40+Opens the iOS Simulator from your command line, dependent on whichever is the active developer directory for Xcode. (That is, it respects the `xcsel` setting.)
41+
42+### `xcselv`
43+
44+Selects different Xcode installations by version name. This is like `xcsel`, except it takes just a version name as an argument instead of the full path to the Xcode installation. Uses the naming conventions described below.
45+
46+* `xcselv <version>` selects a version
47+ * Example: `xcselv 6.2`
48+* `xcselv default` selects the default unversioned `Applications/Xcode.app`
49+* `xcselv` with no argument lists the available Xcode versions in a human-readable format
50+* `xcselv -l` lists the installed Xcode versions
51+* `xcselv -L` lists the installed Xcode versions in a short version-name-only format
52+* `xcselv -p` prints info about the active Xcode version
53+* `xcselv -h` prints a help message
54+
55+The option parsing for `xcselv` is naive. Options may not be combined, and only the first option is recognized.
56+
57+## Multiple Xcode Versions
58+
59+The `xcselv` command provides support for switching between different Xcode installations using just a version number. Different Xcode versions are identified by file naming conventions.
60+
61+### Versioned Xcode Naming Conventions
62+
63diff --git a/plugins/xcode/_xcselv b/plugins/xcode/_xcselv
64new file mode 100644
65index 0000000000000000000000000000000000000000..f9861d54b6e74df6e717658d8573035c4aafd6e3
66--- /dev/null
67+++ b/plugins/xcode/_xcselv
68@@ -0,0 +1,19 @@
69+#compdef xcselv
70+#autoload
71+
72+function _xcselv_compl_list_versions() {
73+ _omz_xcode_list_versions short
74+}
75+
76+_arguments \
77+ '(-l -L -p)-h[prints a help message]' \
78+ '(-L -p -h)-l[lists installed Xcode versions]' \
79+ '(-l -p -h)-L[lists installed Xcode versions (long form)]' \
80+ '(-h -l -L)-p[prints active Xcode version]' \
81+ && ret=0
82+
83+local _xcode_versions
84+_xcode_versions=($(_xcselv_compl_list_versions))
85+_describe -t _xcode_versions 'version' _xcode_versions
86+
87+return 1
88diff --git a/plugins/xcode/xcode.plugin.zsh b/plugins/xcode/xcode.plugin.zsh
89index 1d1205b80887400804f6a45f8d96c17a71507ef4..b63a857a7db47bbc213ec34073b36b4001318d6e 100644
90--- a/plugins/xcode/xcode.plugin.zsh
91+++ b/plugins/xcode/xcode.plugin.zsh
92@@ -1,25 +1,185 @@
93-#xc function courtesy of http://gist.github.com/subdigital/5420709
94+alias xcb='xcodebuild'
95+alias xcdd='rm -rf ~/Library/Developer/Xcode/DerivedData/*'
96+alias xcp='xcode-select --print-path'
97+alias xcsel='sudo xcode-select --switch'
98+
99+# original author: @subdigital
100+# source: http://gist.github.com/subdigital/5420709
101 function xc {
102- xcode_proj=`ls | grep "\.xc" | sort -r | head -1`
103- if [[ `echo -n $xcode_proj | wc -m` == 0 ]]
104- then
105+ local xcode_proj
106+ xcode_proj=(*.{xcworkspace,xcodeproj}(N))
107+
108+ if [[ ${#xcode_proj} -eq 0 ]]; then
109 echo "No xcworkspace/xcodeproj file found in the current directory."
110+ return 1
111 else
112- echo "Found $xcode_proj"
113- open "$xcode_proj"
114+ echo "Found ${xcode_proj[1]}"
115+ open "${xcode_proj[1]}"
116 fi
117 }
118
119-function xcsel {
120- sudo xcode-select --switch "$*"
121+# "XCode-SELect by Version" - select Xcode by just version number
122+# Uses naming convention:
123+# - different versions of Xcode are named Xcode-<version>.app or stored
124+# in a folder named Xcode-<version>
125+# - the special version name "default" refers to the "default" Xcode.app with no suffix
126+function xcselv {
127+ emulate -L zsh
128+ if [[ $# == 0 ]]; then
129+ echo "xcselv: error: no option or argument given" >&2
130+ echo "xcselv: see 'xcselv -h' for help" >&2
131+ return 1
132+ elif [[ $1 == "-p" ]]; then
133+ _omz_xcode_print_active_version
134+ return
135+ elif [[ $1 == "-l" ]]; then
136+ _omz_xcode_list_versions
137+ return
138+ elif [[ $1 == "-L" ]]; then
139+ _omz_xcode_list_versions short
140+ return
141+ elif [[ $1 == "-h" ]]; then
142+ _omz_xcode_print_xcselv_usage
143+ return 0
144+ elif [[ $1 == -* && $1 != "-" ]]; then
145+ echo "xcselv: error: unrecognized option: $1" >&2
146+ echo "xcselv: see 'xcselv -h' for help" >&2
147+ return 1
148+ fi
149+ # Main case: "xcselv <version>" to select a version
150+ local version=$1
151+ local -A xcode_versions
152+ _omz_xcode_locate_versions
153+ if [[ -z ${xcode_versions[$version]} ]]; then
154+ echo "xcselv: error: Xcode version '$version' not found" >&2
155+ return 1
156+ fi
157+ app="${xcode_versions[$version]}"
158+ echo "selecting Xcode $version: $app"
159+ xcsel "$app"
160 }
161
162-alias xcb='xcodebuild'
163-alias xcp='xcode-select --print-path'
164-alias xcdd='rm -rf ~/Library/Developer/Xcode/DerivedData/*'
165+function _omz_xcode_print_xcselv_usage {
166+ cat << EOF >&2
167+Usage:
168+ xcselv <version>
169+ xcselv [options]
170+
171+Options:
172+ <version> set the active Xcode version
173+ -h print this help message and exit
174+ -p print the active Xcode version
175+ -l list installed Xcode versions (long human-readable form)
176+ -L list installed Xcode versions (short form, version names only)
177+EOF
178+}
179+
180+# Parses the Xcode version from a filename based on our conventions
181+# Only meaningful when called from other _omz_xcode functions
182+function _omz_xcode_parse_versioned_file {
183+ local file=$1
184+ local basename=${app:t}
185+ local dir=${app:h}
186+ local parent=${dir:t}
187+ #echo "parent=$parent basename=$basename verstr=$verstr ver=$ver" >&2
188+ local verstr
189+ if [[ $parent == Xcode* ]]; then
190+ if [[ $basename == "Xcode.app" ]]; then
191+ # "Xcode-<version>/Xcode.app" format