Skip to content

Commit baafd69

Browse files
docs: enhance shell completion documentation with practical examples (#2305)
Improve the documentation for shell completion by: - Adding detailed step-by-step setup instructions for each supported shell (Bash, Zsh, Fish, PowerShell) - Including both temporary and permanent setup options - Providing clear examples with copy-paste ready commands - Adding a section on testing completion functionality - Organizing content with clear section headings - Standardizing reference links to related documentation This enhancement makes it easier for users to set up and use shell completion with Chainsaw, improving the overall user experience. Signed-off-by: Karthik babu Manam <[email protected]> Co-authored-by: Charles-Edouard Brétéché <[email protected]>
1 parent 0670f8d commit baafd69

File tree

1 file changed

+110
-7
lines changed

1 file changed

+110
-7
lines changed
+110-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,113 @@
1-
# Shell completion
1+
# Shell Completion
22

3-
Once installed, use `chainsaw completion` command to generate and register the autocompletion script for the specified shell.
3+
Chainsaw provides shell completion support for Bash, Zsh, Fish, and PowerShell. Once set up, you can use the <Tab> key to auto-complete chainsaw commands, flags, and even some arguments, which significantly improves the command-line experience.
44

5-
Supported shells are:
5+
## Generating Completion Scripts
66

7-
- [bash](../reference/commands/chainsaw_completion_bash.md)
8-
- [fish](../reference/commands/chainsaw_completion_fish.md)
9-
- [powershell](../reference/commands/chainsaw_completion_powershell.md)
10-
- [zsh](../reference/commands/chainsaw_completion_zsh.md)
7+
You can generate shell completion scripts using the `chainsaw completion` command:
8+
9+
```bash
10+
# For Bash
11+
chainsaw completion bash
12+
13+
# For Zsh
14+
chainsaw completion zsh
15+
16+
# For Fish
17+
chainsaw completion fish
18+
19+
# For PowerShell
20+
chainsaw completion powershell
21+
```
22+
23+
## Setting Up Completion
24+
25+
### Bash
26+
27+
To enable completion in your current Bash session:
28+
29+
```bash
30+
source <(chainsaw completion bash)
31+
```
32+
33+
To enable completion for all sessions, add the above line to your `~/.bashrc` file:
34+
35+
```bash
36+
echo 'source <(chainsaw completion bash)' >> ~/.bashrc
37+
```
38+
39+
Alternatively, you can save the completion script to the bash-completion directory:
40+
41+
```bash
42+
# On Linux
43+
chainsaw completion bash > /etc/bash_completion.d/chainsaw
44+
45+
# On macOS with Homebrew
46+
chainsaw completion bash > $(brew --prefix)/etc/bash_completion.d/chainsaw
47+
```
48+
49+
### Zsh
50+
51+
To enable completion in your current Zsh session:
52+
53+
```bash
54+
source <(chainsaw completion zsh)
55+
```
56+
57+
To enable completion for all sessions, add the above line to your `~/.zshrc` file:
58+
59+
```bash
60+
echo 'source <(chainsaw completion zsh)' >> ~/.zshrc
61+
```
62+
63+
Alternatively, you can save the completion script to a directory in your `$fpath`:
64+
65+
```bash
66+
# Create a directory for completions if it doesn't exist
67+
mkdir -p ~/.zsh/completion
68+
# Generate and save the completion script
69+
chainsaw completion zsh > ~/.zsh/completion/_chainsaw
70+
71+
# Make sure the directory is in your fpath by adding to ~/.zshrc:
72+
echo 'fpath=(~/.zsh/completion $fpath)' >> ~/.zshrc
73+
echo 'autoload -U compinit; compinit' >> ~/.zshrc
74+
```
75+
76+
### Fish
77+
78+
To enable completion in Fish:
79+
80+
```bash
81+
chainsaw completion fish > ~/.config/fish/completions/chainsaw.fish
82+
```
83+
84+
### PowerShell
85+
86+
To enable completion in PowerShell:
87+
88+
```powershell
89+
chainsaw completion powershell | Out-String | Invoke-Expression
90+
```
91+
92+
To make it persistent, add the above line to your PowerShell profile:
93+
94+
```powershell
95+
# Find the profile path
96+
echo $PROFILE
97+
98+
# Add the completion command to your profile
99+
chainsaw completion powershell | Out-String | Out-File -Append $PROFILE
100+
```
101+
102+
## Testing Completion
103+
104+
After setting up completion, you can test it by typing `chainsaw` followed by a space and pressing <Tab>. This should show available subcommands. You can also try typing partial commands like `chainsaw te` and then pressing <Tab>, which should complete to `chainsaw test`.
105+
106+
## Detailed Reference
107+
108+
For more detailed information about each completion command, see the reference documentation:
109+
110+
- [Bash Completion](../reference/commands/chainsaw_completion_bash.md)
111+
- [Fish Completion](../reference/commands/chainsaw_completion_fish.md)
112+
- [PowerShell Completion](../reference/commands/chainsaw_completion_powershell.md)
113+
- [Zsh Completion](../reference/commands/chainsaw_completion_zsh.md)

0 commit comments

Comments
 (0)