|
| 1 | +# Shell Completion for slcli |
| 2 | + |
| 3 | +The SystemLink CLI supports shell completion for bash, zsh, fish, and PowerShell shells with dynamic command discovery. |
| 4 | + |
| 5 | +## Dynamic Completion |
| 6 | + |
| 7 | +- **PowerShell**: Commands extracted from CLI structure at generation time |
| 8 | +- **Bash/Zsh/Fish**: Uses Click's built-in completion system |
| 9 | +- Always up-to-date with current CLI commands |
| 10 | +- Automatically stays current when new commands are added |
| 11 | + |
| 12 | +## Quick Installation |
| 13 | + |
| 14 | +### Automatic Installation (Recommended) |
| 15 | + |
| 16 | +```bash |
| 17 | +# Install completion for your current shell |
| 18 | +slcli completion --install |
| 19 | + |
| 20 | +# Or specify a shell explicitly |
| 21 | +slcli completion --shell bash --install |
| 22 | +slcli completion --shell zsh --install |
| 23 | +slcli completion --shell fish --install |
| 24 | +slcli completion --shell powershell --install |
| 25 | +``` |
| 26 | + |
| 27 | +### Manual Installation |
| 28 | + |
| 29 | +#### Bash |
| 30 | + |
| 31 | +1. Generate completion script: |
| 32 | + |
| 33 | + ```bash |
| 34 | + slcli completion --shell bash > ~/.bash_completion.d/slcli |
| 35 | + ``` |
| 36 | + |
| 37 | +2. Source the completion (add to ~/.bashrc for persistence): |
| 38 | + ```bash |
| 39 | + source ~/.bash_completion.d/slcli |
| 40 | + ``` |
| 41 | + |
| 42 | +#### Zsh |
| 43 | + |
| 44 | +1. Create completion directory and generate script: |
| 45 | + |
| 46 | + ```bash |
| 47 | + mkdir -p ~/.zsh_completions |
| 48 | + slcli completion --shell zsh > ~/.zsh_completions/_slcli |
| 49 | + ``` |
| 50 | + |
| 51 | +2. Add to your ~/.zshrc: |
| 52 | + ```bash |
| 53 | + fpath=(~/.zsh_completions $fpath) |
| 54 | + autoload -U compinit && compinit |
| 55 | + ``` |
| 56 | + |
| 57 | +#### Fish |
| 58 | + |
| 59 | +1. Generate completion script: |
| 60 | + ```bash |
| 61 | + slcli completion --shell fish > ~/.config/fish/completions/slcli.fish |
| 62 | + ``` |
| 63 | + |
| 64 | +Fish will automatically load the completion on next shell restart. |
| 65 | + |
| 66 | +#### PowerShell |
| 67 | + |
| 68 | +1. Generate completion script: |
| 69 | + |
| 70 | + ```powershell |
| 71 | + slcli completion --shell powershell > $env:USERPROFILE\Documents\PowerShell\slcli_completion.ps1 |
| 72 | + ``` |
| 73 | + |
| 74 | +2. Add to your PowerShell profile: |
| 75 | + |
| 76 | + ```powershell |
| 77 | + # Add this line to your $PROFILE |
| 78 | + . $env:USERPROFILE\Documents\PowerShell\slcli_completion.ps1 |
| 79 | + ``` |
| 80 | + |
| 81 | + Or run this command to add it automatically: |
| 82 | + |
| 83 | + ```powershell |
| 84 | + Add-Content $PROFILE ". `$env:USERPROFILE\Documents\PowerShell\slcli_completion.ps1" |
| 85 | + ``` |
| 86 | + |
| 87 | +## Using the Installation Script |
| 88 | + |
| 89 | +You can also use the dedicated installation script: |
| 90 | + |
| 91 | +```bash |
| 92 | +# Install for current shell (auto-detected) |
| 93 | +python scripts/install_completion.py |
| 94 | + |
| 95 | +# Install for specific shell |
| 96 | +python scripts/install_completion.py bash |
| 97 | +python scripts/install_completion.py zsh |
| 98 | +python scripts/install_completion.py fish |
| 99 | +python scripts/install_completion.py powershell |
| 100 | +``` |
| 101 | + |
| 102 | +## What Gets Completed |
| 103 | + |
| 104 | +The completion system will help with: |
| 105 | + |
| 106 | +- Command names (`user`, `workspace`, `template`, etc.) |
| 107 | +- Subcommands (`list`, `get`, `create`, `update`, `delete`) |
| 108 | +- Option names (`--format`, `--filter`, `--id`, etc.) |
| 109 | +- Option values for choices (e.g., `--format` will complete `table` and `json`) |
| 110 | + |
| 111 | +## Troubleshooting |
| 112 | + |
| 113 | +### Completion Not Working |
| 114 | + |
| 115 | +1. Verify slcli is in your PATH: |
| 116 | + |
| 117 | + ```bash |
| 118 | + which slcli |
| 119 | + ``` |
| 120 | + |
| 121 | +2. Test completion generation: |
| 122 | + |
| 123 | + ```bash |
| 124 | + slcli completion --shell bash # Should output bash completion script |
| 125 | + ``` |
| 126 | + |
| 127 | +3. For bash, ensure bash-completion is installed: |
| 128 | + |
| 129 | + ```bash |
| 130 | + # Ubuntu/Debian |
| 131 | + sudo apt install bash-completion |
| 132 | + |
| 133 | + # macOS with Homebrew |
| 134 | + brew install bash-completion |
| 135 | + ``` |
| 136 | + |
| 137 | +4. Restart your shell or source the completion file manually. |
| 138 | + |
| 139 | +### Permission Issues |
| 140 | + |
| 141 | +If you get permission errors during installation, try: |
| 142 | + |
| 143 | +1. Install to user directory instead of system-wide |
| 144 | +2. Run with appropriate permissions for system directories |
| 145 | +3. Use the manual installation method |
| 146 | + |
| 147 | +### PowerShell Module Not Loading |
| 148 | + |
| 149 | +For PowerShell completion issues: |
| 150 | + |
| 151 | +1. Check if execution policy allows script loading: |
| 152 | + |
| 153 | + ```powershell |
| 154 | + Get-ExecutionPolicy |
| 155 | + ``` |
| 156 | + |
| 157 | +2. If restricted, set execution policy (as Administrator): |
| 158 | + |
| 159 | + ```powershell |
| 160 | + Set-ExecutionPolicy RemoteSigned |
| 161 | + ``` |
| 162 | + |
| 163 | +3. Verify your profile exists: |
| 164 | + |
| 165 | + ```powershell |
| 166 | + Test-Path $PROFILE |
| 167 | + ``` |
| 168 | + |
| 169 | +4. Create profile if it doesn't exist: |
| 170 | + ```powershell |
| 171 | + New-Item -Path $PROFILE -ItemType File -Force |
| 172 | + ``` |
| 173 | + |
| 174 | +## Advanced Usage |
| 175 | + |
| 176 | +### Custom Completion Location |
| 177 | + |
| 178 | +You can save completion scripts to custom locations: |
| 179 | + |
| 180 | +```bash |
| 181 | +# Save to custom file |
| 182 | +slcli completion --shell bash > /path/to/custom/completion |
| 183 | + |
| 184 | +# Source it manually |
| 185 | +source /path/to/custom/completion |
| 186 | +``` |
| 187 | + |
| 188 | +### Integration with Package Managers |
| 189 | + |
| 190 | +If you're distributing slcli via package managers, consider: |
| 191 | + |
| 192 | +- **Homebrew**: Include completion in formula |
| 193 | +- **APT/RPM**: Install completion to standard system directories |
| 194 | +- **pip**: Use post-install hooks to offer completion installation |
0 commit comments