Skip to content
Branch: master
Find file Copy path
Find file Copy path
3 contributors

Users who have contributed to this file

@Bouke @jakepetroules @BenchR267
98 lines (81 sloc) 2.99 KB
This source file is part of the open source project
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See for license information
See for Swift project authors
import Foundation
import TSCBasic
import TSCUtility
/// Template for ZSH completion script.
/// - Parameter stream: output stream to write the script to.
func zsh_template(on stream: OutputByteStream) {
stream <<< """
#compdef swift
local context state state_descr line
typeset -A opt_args
_swift() {
_arguments -C \\
'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \\
'(-): :->command' \\
'(-)*:: :->arg' && return
case $state in
local tools
'build:build sources into binary products'
'run:build and run an executable product'
'package:perform operations on Swift packages'
'test:build and run tests'
_alternative \\
'tools:common:{_describe \"tool\" tools }' \\
'compiler: :_swift_compiler' && _ret=0
case ${words[1]} in
_swift_dependency() {
local dependencies
dependencies=( $(\(listDependenciesCommand)) )
_describe '' dependencies
_swift_executable() {
local executables
executables=( $(\(listExecutablesCommand)) )
_describe '' executables
SwiftBuildTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
SwiftRunTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
SwiftPackageTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
SwiftTestTool(args: []).parser.generateCompletionScript(for: .zsh, on: stream)
// Figure out how to forward to swift compiler's bash completion.
stream <<< """
_swift_compiler() {
// Run the `_swift` function to register the completions.
stream <<< "_swift\n"
You can’t perform that action at this time.