// ZSH-XCODE-COMPLETIONS — ZSH COMPLETIONS FOR THE XCODE COMMAND-LINE TOOLS

zsh plugin · completions for xcodebuild, xcrun, genstrings, nm, plutil, xcode-select, strings, swift, swift-demangle · xcrun-shim binaries for nested completion

GitHub Issues
// Color scheme

>_ZSH-XCODE-COMPLETIONS

Xcode command-line tools, completed. Zsh completions for the Xcode command-line tools, with xcrun-shim binaries to work around xcrun's nested-command completion limitation.

Install

# Homebrew (recommended)
brew install keith/formulae/zsh-xcode-completions

# Zinit
zinit ice lucid nocompile
zinit load MenkeTechnologies/zsh-xcode-completions

# Oh My Zsh
git clone https://github.com/MenkeTechnologies/zsh-xcode-completions \
    "$HOME/.oh-my-zsh/custom/plugins/zsh-xcode-completions"
# then: plugins+=(zsh-xcode-completions)

# Manual
git clone https://github.com/MenkeTechnologies/zsh-xcode-completions
# source the plugin file or copy _* files onto your fpath

The Homebrew formula installs the shim binaries to PATH. If you don't want shims, install with --without-shims.

Covered binaries

Eleven #compdef completers live under src/, one per tool. Each is autoloaded by zsh's completion system after the plugin prepends src/ to fpath.

xcodebuildbuild / analyze / archive / test / install — 31 flags + 7 build actions, project-aware
xcrunlocate / run developer tools (with shim for nested completion)
xcode-selectswitch / print / reset active developer directory
genstringsextract .strings from source
nmsymbol-table dump — 18 flags incl. -arch enum
stringsprintable-string extraction — flags + -arch enum
dyldinfodyld load-command / binding / rebase inspector
plutilproperty-list lint / convert / extract / edit
instrumentsprofiling — template + attach-pid completion
swiftSwift compiler driver — emit / search-path / SDK flags
swift-demangledemangle Swift symbols

Examples

Every example below maps to a real completion state in one of the src/_* files. Press TAB at the cursor:

xcodebuild -scheme <TAB>          # schemes parsed from `xcodebuild -list`
xcodebuild -target <TAB>          # targets parsed from `xcodebuild -list`
xcodebuild -configuration <TAB>   # configs parsed from `xcodebuild -list`
xcodebuild -arch <TAB>            # VALID_ARCHS from `xcodebuild -showBuildSettings`
xcodebuild -sdk <TAB>             # cached SDK list (`xcodebuild -showsdks`)
xcodebuild -project <TAB>         # glob *.xcodeproj
xcodebuild -workspace <TAB>       # glob *.xcworkspace
xcodebuild <TAB>                  # build actions: build/clean/test/archive/…
xcrun <TAB>                       # tools in $(dirname $(xcrun -f swift))
xcrun --sdk <TAB>                 # cached SDK platforms
xcrun --toolchain <TAB>           # glob installed .xctoolchain dirs
xcode-select --switch <TAB>       # glob /Applications/Xcode*.app
plutil -convert <TAB>             # json / xml1 / binary1
nm -arch <TAB>                    # arm64 / armv7 / armv7s / i386 / x86_64
instruments -t <TAB>              # templates from `instruments -s templates`

Per-tool flag reference

Every flag below is taken directly from the src/_* completers. Flags marked with “→” offer value completion at the next TAB.

xcodebuild31 flags. Project-aware values: -scheme→, -target→, -configuration→, -arch→, -sdk→, -project*.xcodeproj, -workspace*.xcworkspace, -xcconfig*.xcconfig. Path values: -archivePath, -derivedDataPath, -resultBundlePath. Toggles (YES/NO): -enableAddressSanitizer, -enableThreadSanitizer, -enableUndefinedBehaviorSanitizer, -enableCodeCoverage. Switches: -n/-dry-run, -alltargets, -list, -showsdks, -showBuildSettings, -skipUnavailableActions, -usage, -version. Archive/export: -exportArchive, -exportFormat (IPA/PKG/APP), -exportInstallerIdentity, -exportProvisiningProfile, -exportSigningIdentity, -exportWithOriginalSigningIdentity, -destination, -destination-timeout. Actions: analyze, archive, build, clean, install, installsrc, test.
xcrun-f/--find, -h/--help, -k/--kill-cache, -l/--log, -n/--no-cache, -r/--run, -v/--verbose, --sdk→, --toolchain→, --show-sdk-path, --show-sdk-platform-path, --show-sdk-platform-version, --show-sdk-version, --version. Positional tool name completes from $(dirname $(xcrun -f swift)).
xcode-select-h/--help, -p/--print-path, -r/--reset, -s/--switch→ (glob /Applications/Xcode*.app), -v/--version, --install.
swift-assert-config (Debug/Release/Replacement), -D, -emit-assembly, -emit-library, -emit-object, -F→, -framework→, -g, -gline-tables-only, -gnone, -help, -I→, -j, -L→, -l→, -module-cache-path→, -module-link-name, -module-name, -nostdimport, -O, -o→, -Onone, -Ounchecked, -sdk→ (cached), -target-cpu, -target, -v, -version, -Xcc, -Xlinker.
swift-demangle-classify, -compact, -expand, -help, -help-list-hidden, -no-sugar, -remangle-new, -simplified, -test-remangle, -tree-only, -version. Positional args are the symbol(s) to demangle.
nm-a, -A, -arch→ (arm64/armv7/armv7s/i386/x86_64), -f, -g, -j, -l, -m, -n, -o, -p, -P, -r, -s, -t (d/o/x), -u, -U, -x. Positional → files.
strings- (all bytes), -a (all sections), -arch→ (same enum as nm), -n (min length), -o (offset), -t (d/o/x). Positional → files.
dyldinfo-arch→ (i386/x86_64/armv7/arm64), -dylibs, -rebase, -bind, -weak_bind, -lazy_bind, -export, -opcodes, -function_starts. Positional → Mach-O files.
plutil-convert→ (json/xml1/binary1), -insert, -replace (both: keypath → type -bool/-integer/-float/-string/-date/-data/-xml/-json → value), -remove, -extract→, -e, -help, -lint, -o→, -p, -r, -s. Positional → files.
instruments-w (target device/sim), -v, -t→ (templates, cached), -s (templates/devices), -D→ (trace doc), -l (time limit), -i (instrument index). Mutex modes: -p_pids (attach) vs. positional command name (launch).
genstrings-a, -macRoman, -noPositionalParameters, -o→ (output dir), -q, -s (custom NSLocalizedString fn), -skipTable, -u. Positional → source files.

How completion data is sourced

Most static flags are inline enums, but the context-sensitive values are queried live at TAB time:

schemes / targets / configurationsxcodebuild -list, section-sliced with sed
valid archsxcodebuild -showBuildSettings | grep VALID_ARCHS | cut -f2 -d=
SDK listxcodebuild -showsdks, cached under key SDKS (shared by xcodebuild + swift) and SDK_PLATFORMS (xcrun)
xcrun tool namesls $(dirname $(xcrun -f swift))
toolchainsglob /Applications/Xcode*.app/Contents/Developer/Toolchains/*.xctoolchain
instruments templatesinstruments -s templates${(Q)${(f)...}} split/unquote, header dropped, cached as _instruments_templates

Configuration

  • fpath — the plugin's sole job is fpath=("${0:h}/src" $fpath). Whatever loader you use must run compinit after sourcing the plugin so the _* files are picked up.
  • Completion cache — SDK lists use zsh's _store_cache / _retrieve_cache. To benefit, enable the cache policy in your .zshrc: zstyle ':completion:*' use-cache on. Cache keys: SDKS, SDK_PLATFORMS, _instruments_templates. Reinstalling an SDK invalidates SDKS for both xcodebuild and swift.
  • Shims — the Homebrew formula installs bin/swift-demangle (a #!/bin/sh wrapper running xcrun swift-demangle "$@") onto PATH so the _swift-demangle completer can fire. Install with --without-shims to skip it. Tradeoff: you cannot pass arguments to xcrun itself when calling through a shim.

Troubleshooting

  • No completions appear — confirm compinit runs after the plugin loads, and that src/ is on fpath (echo $fpath | tr ' ' '\n' | grep zsh-xcode).
  • Stale SDK / scheme list — the SDK list is cached; clear it with rm "$ZSH_COMPDUMP"* and the zsh completion cache dir, or just open a new shell. Scheme/target/config lists are not cached and re-query xcodebuild -list every TAB.
  • Project queries are slow — each -scheme/-target/-arch TAB spawns xcodebuild, which is inherently slow in large projects. This is the cost of project-correct values over static enums.
  • swift-demangle won't complete through xcrun — that is the limitation the shim exists for. Either install the shim (default Homebrew behavior) or invoke swift-demangle as a direct PATH binary.

Sibling plugins

Part of the MenkeTechnologies zsh plugin family — the MenkeTechnologiesMeta umbrella: