feat: add shell completion for host names (#37)

- Add ValidArgsFunction to RootCmd for dynamic host completion
- Add 'sshm completion' subcommand for bash/zsh/fish/powershell
- Support prefix matching and case-insensitive filtering
- Respect --config flag for custom SSH config files
- Add comprehensive tests for completion functionality
- Document setup instructions in README

Co-authored-by: Guillaume Archambault <67098259+Gu1llaum-3@users.noreply.github.com>
This commit is contained in:
David Ibia
2026-01-04 19:37:52 +01:00
committed by GitHub
parent 435597f694
commit 2f9587c8c8
4 changed files with 423 additions and 0 deletions

View File

@@ -275,6 +275,53 @@ sshm --version
sshm --help
```
### Shell Completion
SSHM supports shell completion for host names, making it easy to connect to hosts without typing full names:
```bash
sshm <TAB> # Lists all available hosts
sshm pro<TAB> # Completes to hosts starting with "pro" (e.g., prod-server)
```
**Setup Instructions:**
**Bash:**
```bash
# Enable for current session
source <(sshm completion bash)
# Enable permanently (add to ~/.bashrc)
echo 'source <(sshm completion bash)' >> ~/.bashrc
```
**Zsh:**
```bash
# Enable for current session
source <(sshm completion zsh)
# Enable permanently (add to ~/.zshrc)
echo 'source <(sshm completion zsh)' >> ~/.zshrc
```
**Fish:**
```bash
# Enable for current session
sshm completion fish | source
# Enable permanently
sshm completion fish > ~/.config/fish/completions/sshm.fish
```
**PowerShell:**
```powershell
# Enable for current session
sshm completion powershell | Out-String | Invoke-Expression
# Enable permanently (add to your PowerShell profile)
Add-Content $PROFILE 'sshm completion powershell | Out-String | Invoke-Expression'
```
### Direct Host Connection
SSHM supports direct connection to hosts via the command line, making it easy to integrate into your existing workflow: