Skip to content

Commit c42b6f3

Browse files
committed
Add shell completion instructions for vm command in README.md
1 parent 24d3842 commit c42b6f3

14 files changed

Lines changed: 96 additions & 12 deletions

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,69 @@ This boots a Fedora Cloud rescue system with the target VM's disk attached as `/
126126

127127
On first run, a rescue image is downloaded and set up (~500MB download). The `rescue` use is logged in automatically, however both the `rescue` and `root` user have their passwords set to `rescue`.
128128

129+
## Shell completion
130+
131+
`vm` supports tab-completion for subcommands, options, and VM names. Generate a completion script for your shell and source it (or install it in your shell’s completion directory).
132+
133+
### Generate the script
134+
135+
```bash
136+
# Auto-detect shell
137+
vm --generate-completion-script
138+
139+
# Or specify the shell explicitly
140+
vm --generate-completion-script bash
141+
vm --generate-completion-script zsh
142+
vm --generate-completion-script fish
143+
```
144+
145+
### Bash
146+
147+
Append the generated script to your `~/.bashrc` or load it once:
148+
149+
```bash
150+
vm --generate-completion-script bash >> ~/.bashrc
151+
# then start a new shell, or:
152+
source ~/.bashrc
153+
```
154+
155+
Or install to a completions directory (e.g. on macOS with Homebrew bash):
156+
157+
```bash
158+
vm --generate-completion-script bash > $(brew --prefix)/etc/bash_completion.d/vm
159+
```
160+
161+
### Zsh
162+
163+
Load the script from your `.zshrc`:
164+
165+
```bash
166+
# Add to ~/.zshrc
167+
source <(vm --generate-completion-script zsh)
168+
```
169+
170+
Or install for all users (e.g. into a site-functions directory):
171+
172+
```bash
173+
vm --generate-completion-script zsh > /usr/local/share/zsh/site-functions/_vm
174+
```
175+
176+
With oh-my-zsh, put the script in your completions folder:
177+
178+
```bash
179+
vm --generate-completion-script zsh > ~/.oh-my-zsh/completions/_vm
180+
```
181+
182+
### Fish
183+
184+
Save the script to Fish’s completions directory:
185+
186+
```bash
187+
vm --generate-completion-script fish > ~/.config/fish/completions/vm.fish
188+
```
189+
190+
Start a new shell or run `fish_update_completions` so Fish picks it up.
191+
129192
## VM Storage
130193

131194
VMs are stored in `~/.vm/` with each VM in its own directory:

Sources/VM/Commands/Attach.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Attach: AsyncParsableCommand {
1616
aliases: ["console"]
1717
)
1818

19-
@Argument(help: "Name of the virtual machine to attach to")
19+
@Argument(help: "Name of the virtual machine to attach to", completion: VMNameCompletion.kind)
2020
var name: String
2121

2222
@MainActor

Sources/VM/Commands/Delete.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct Delete: AsyncParsableCommand {
1818
"""
1919
)
2020

21-
@Argument(help: "Name of the virtual machine to delete")
21+
@Argument(help: "Name of the virtual machine to delete", completion: VMNameCompletion.kind)
2222
var name: String
2323

2424
@Flag(name: .shortAndLong, help: "Skip confirmation prompt")

Sources/VM/Commands/Edit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Edit: AsyncParsableCommand {
1616
"""
1717
)
1818

19-
@Argument(help: "Name of the virtual machine")
19+
@Argument(help: "Name of the virtual machine", completion: VMNameCompletion.kind)
2020
var name: String
2121

2222
@Option(name: .long, help: "Number of CPU cores")

Sources/VM/Commands/IP.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct IP: AsyncParsableCommand {
1919
shouldDisplay: false
2020
)
2121

22-
@Argument(help: "Name of the virtual machine")
22+
@Argument(help: "Name of the virtual machine", completion: VMNameCompletion.kind)
2323
var name: String
2424

2525
mutating func run() async throws {

Sources/VM/Commands/Info.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct Info: AsyncParsableCommand {
7070
"""
7171
)
7272

73-
@Argument(help: "Name of the virtual machine")
73+
@Argument(help: "Name of the virtual machine", completion: VMNameCompletion.kind)
7474
var name: String
7575

7676
@Option(help: "Output format")

Sources/VM/Commands/RegenCloudInitISO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct RegenCloudInitISO: AsyncParsableCommand {
1919
shouldDisplay: false
2020
)
2121

22-
@Argument(help: "Name of the virtual machine")
22+
@Argument(help: "Name of the virtual machine", completion: VMNameCompletion.kind)
2323
var name: String
2424

2525
@MainActor

Sources/VM/Commands/Rescue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct Rescue: AsyncParsableCommand {
9393
"""
9494
)
9595

96-
@Argument(help: "Name of the virtual machine to rescue")
96+
@Argument(help: "Name of the virtual machine to rescue", completion: VMNameCompletion.kind)
9797
var name: String
9898

9999
@Flag(name: .long, help: "Force re-download and setup of rescue VM")

Sources/VM/Commands/Resize.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Resize: AsyncParsableCommand {
1717
"""
1818
)
1919

20-
@Argument(help: "Name of the virtual machine")
20+
@Argument(help: "Name of the virtual machine", completion: VMNameCompletion.kind)
2121
var name: String
2222

2323
@Option(name: .long, help: "New disk size (e.g., 128G, 256G, 512G)")

Sources/VM/Commands/RunDaemon.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct RunDaemon: AsyncParsableCommand {
1212
shouldDisplay: false // Hidden from help
1313
)
1414

15-
@Argument(help: "Name of the virtual machine to run")
15+
@Argument(help: "Name of the virtual machine to run", completion: VMNameCompletion.kind)
1616
var name: String
1717

1818
@Flag(name: .long, help: "Boot from ISO image (for installation)")

0 commit comments

Comments
 (0)