Skip to content

Commit 8aa8d18

Browse files
authored
Create documentation for shell auto-completions (swiftlang#200)
1 parent acd2139 commit 8aa8d18

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

Documentation/SwiftlyDocs.docc/SwiftlyDocs.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Install and manage your Swift programming language toolchains.
1414

1515
- <doc:install-toolchains>
1616
- <doc:use-toolchains>
17+
- <doc:shell-autocompletion>
1718
- <doc:uninstall-toolchains>
1819
- <doc:update-toolchain>
1920
- <doc:automated-install>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Add Shell Auto-completions
2+
3+
Swiftly can generate shell auto-completion scripts for your shell to automatically complete subcommands, arguments, options and flags. It does this using the [swift-argument-parser](https://apple.github.io/swift-argument-parser/documentation/argumentparser/installingcompletionscripts/), which has support for Bash, Z shell, and Fish.
4+
5+
You can ask swiftly to generate the script using the hidden `--generate-completion-script` flag with the type of shell like this:
6+
7+
```
8+
swiftly --generate-completion-script <shell>
9+
```
10+
11+
@TabNavigator {
12+
@Tab("zsh") {
13+
If you have [oh-my-zsh](https://ohmyz.sh/) installed then this command will install the swiftly completions into the default directory:
14+
15+
```
16+
swiftly --generate-completion-script zsh > ~/.oh-my-zsh/completions/_swiftly
17+
```
18+
19+
Otherwise, you'll need to add a path for completion scripts to your function path, and turn on completion script autoloading. First, add these lines to ~/.zshrc:
20+
21+
```
22+
fpath=(~/.zsh/completion $fpath)
23+
autoload -U compinit
24+
compinit
25+
```
26+
27+
Next, create the completion directory and add the swiftly completions to it:
28+
29+
```
30+
mkdir -p ~/.zsh/completion && swiftly --generate-completion-script zsh > ~/.zsh/completions/swiftly
31+
```
32+
}
33+
34+
@Tab("bash") {
35+
If you have [bash-completion](https://github.com/scop/bash-completion) installed then this command will install the swiftly completions into the default directory:
36+
37+
```
38+
swiftly --generate-completion-script bash > swiftly.bash
39+
# copy swiftly.bash to /usr/local/etc/bash_completion.d
40+
```
41+
42+
Without bash-completion create a directory for the completion and generate the script in there:
43+
44+
```
45+
mkdir -p ~/.bash_completions && swiftly --generate-completion-script bash > ~/.bash_completions/swiftly.bash
46+
```
47+
48+
Add a line to source that script in your `~/.bash_profile` or `~/.bashrc` file:
49+
50+
```
51+
source ~/.bash_completions/swiftly.bash
52+
```
53+
}
54+
55+
@Tab("fish") {
56+
Generate the completion script to any path in the environment variable `$fish_completion_path`. Typically this command will generate the script in the right place:
57+
58+
```
59+
swiftly --generate-completion-script fish > ~/.config/fish/completions/swiftly.fish
60+
```
61+
}
62+
}
63+
64+
Once you have installed the completions you can type out a swiftly command, and press a special key (e.g. tab) and the shell will show you the available subcommand, argument, or options to make it easier to assemble a working command-line.

0 commit comments

Comments
 (0)