Skip to content

Commit 883cdf0

Browse files
committed
Merge feature/shell-completions: add shell autocompletion (v1.6.0)
2 parents 341f6f1 + 7ce9caa commit 883cdf0

15 files changed

Lines changed: 1031 additions & 19 deletions

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pm run order-service
181181
- 🛡️ **Robust auto-update** - Download integrity validation, redirect loop protection, descriptive network error messages
182182
- 🐳 **Docker support** - Detect Docker Compose projects, default commands (build, up, down, clean)
183183
- 🪝 **Pre-/post-command hooks** - Run custom scripts before or after any command with `pm hooks`
184+
- 🔤 **Shell autocompletion** - TAB completion for bash, zsh, fish, and PowerShell with `pm completions`
184185
- 🌐 **Multi-platform** - Works on Windows, Linux, and Mac
185186

186187
---
@@ -236,6 +237,7 @@ chmod +x scripts/install.sh && ./scripts/install.sh
236237
| `pm hooks <name> add <slot> "<script>"` | Add a pre-/post-command hook |
237238
| `pm hooks <name> remove <slot> "<script>"` | Remove a hook |
238239
| `pm hooks --all` | List hooks for all projects |
240+
| `pm completions <shell>` | Generate completion script (bash/zsh/fish/powershell) |
239241
| `pm rename <old> <new>` | Rename a project |
240242
| `pm rename <name> --path <path>` | Update project path |
241243
| `pm refresh <name>` | Re-detect project type and update commands |
@@ -451,9 +453,9 @@ Projects are saved in:
451453
- **CLI**`pm doctor`, `pm env`, `pm refresh`, `pm rename`, `pm update`, `pm commands add/remove`
452454
- **Runtimes** — Gradle, Maven, Node.js, .NET, Python, Rust, Go, pnpm, Bun, Yarn, Flutter, Docker
453455
- **Integrations** — Git status, interactive TTY, multi-platform installers, GitHub Actions
454-
- **Reliability** — Atomic writes, backup/recovery, directory validation, download integrity, 357 tests
456+
- **Reliability** — Atomic writes, backup/recovery, directory validation, download integrity, 402 tests
455457

456-
> Latest release: **v1.5.0** (Pre-/Post-Command Hooks) — Full version history in [ROADMAP.md](ROADMAP.md)
458+
> Latest release: **v1.6.0** (Shell Autocompletion) — Full version history in [ROADMAP.md](ROADMAP.md)
457459
458460
### 💡 Future Ideas
459461
- [ ] `pm run-all` / `pm build-all` - Execute commands across all projects

ROADMAP.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,20 @@ Run custom scripts automatically before or after any command. Hooks are per-proj
166166

167167
---
168168

169-
## v1.6.0 — Shell Autocompletion
169+
## v1.6.0 — Shell Autocompletion
170170

171171
### `pm completions` command
172-
- Generate completion scripts for bash, zsh, fish, and PowerShell
173-
- `pm completions <shell>` — output completion script for the specified shell
174-
- Autocomplete project names, commands, and flags
175-
- Zero dependencies — generates static shell scripts
172+
173+
| Feature | Status |
174+
|---------|--------|
175+
| `pm completions bash` — generate Bash completion script | ✅ Done |
176+
| `pm completions zsh` — generate Zsh completion script | ✅ Done |
177+
| `pm completions fish` — generate Fish completion script | ✅ Done |
178+
| `pm completions powershell` — generate PowerShell completion script | ✅ Done |
179+
| Autocomplete top-level commands, project names, subcommands, and flags | ✅ Done |
180+
| Context-aware completions (hook slots, env var keys, project types) | ✅ Done |
181+
| Hidden `--complete` callback skips banner/update for performance | ✅ Done |
182+
| Zero dependencies — generates static shell scripts | ✅ Done |
176183

177184
---
178185

User-Guide.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [Command Execution](#-command-execution)
1414
- [Rename & Path Update](#-rename--path-update)
1515
- [Pre-/Post-Command Hooks](#-prepost-command-hooks)
16+
- [Shell Autocompletion](#-shell-autocompletion)
1617
- [Environment Variable Management](#-environment-variable-management)
1718
- [Diagnostics](#-diagnostics)
1819
- [Help and Version](#-help-and-version)
@@ -492,6 +493,49 @@ pm hooks my-api remove pre-build "npm run lint"
492493

493494
---
494495

496+
### 🔹 Shell Autocompletion
497+
498+
Enable TAB completion for all `pm` commands, project names, and subcommands.
499+
500+
#### Generate completion script
501+
```bash
502+
pm completions <shell>
503+
```
504+
505+
#### Setup
506+
507+
**Bash** — add to `~/.bashrc`:
508+
```bash
509+
eval "$(pm completions bash)"
510+
```
511+
512+
**Zsh** — add to `~/.zshrc`:
513+
```bash
514+
eval "$(pm completions zsh)"
515+
```
516+
517+
**Fish** — save to completions directory:
518+
```bash
519+
pm completions fish > ~/.config/fish/completions/pm.fish
520+
```
521+
522+
**PowerShell** — add to `$PROFILE`:
523+
```powershell
524+
pm completions powershell | Out-String | Invoke-Expression
525+
```
526+
527+
#### What gets autocompleted?
528+
529+
- **Top-level commands**`pm b<TAB>``build`
530+
- **Project names**`pm build <TAB>` → lists all registered projects
531+
- **Subcommands**`pm env <TAB>``set`, `get`, `list`, `remove`, `clear`
532+
- **Flags**`pm add myproject <TAB>``--path`, `--type`, `--env`
533+
- **Hook slots**`pm hooks myproject add <TAB>``pre-build`, `post-run`, etc.
534+
- **Env var keys**`pm env get myproject <TAB>` → lists configured variable names
535+
- **Shell names**`pm completions <TAB>``bash`, `zsh`, `fish`, `powershell`
536+
537+
---
538+
495539
### 🔹 Environment Variable Management
496540

497541
#### Set variables
@@ -1559,6 +1603,12 @@ pm rename <old> <new> --path <path> # Both at once
15591603
pm refresh <name> # Re-detect type and update commands
15601604
pm refresh --all # Refresh all projects
15611605

1606+
# === SHELL AUTOCOMPLETION ===
1607+
pm completions bash # Generate Bash completion script
1608+
pm completions zsh # Generate Zsh completion script
1609+
pm completions fish # Generate Fish completion script
1610+
pm completions powershell # Generate PowerShell completion script
1611+
15621612
# === DIAGNOSTICS ===
15631613
pm doctor # Check environment health
15641614

docs/es/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pm run servicio-pedidos
181181
- 🛡️ **Auto-update robusto** - Validación de integridad de descarga, protección contra loops de redirección, mensajes de error de red descriptivos
182182
- 🐳 **Soporte Docker** - Detecta proyectos Docker Compose, comandos por defecto (build, up, down, clean)
183183
- 🪝 **Hooks pre-/post-comando** - Ejecuta scripts personalizados antes o después de cualquier comando con `pm hooks`
184+
- 🔤 **Autocompletado en shell** - Completado con TAB para bash, zsh, fish y PowerShell con `pm completions`
184185
- 🌐 **Multi-plataforma** - Funciona en Windows, Linux y Mac
185186

186187
---
@@ -236,6 +237,7 @@ chmod +x scripts/install.sh && ./scripts/install.sh
236237
| `pm hooks <nombre> add <slot> "<script>"` | Añadir un hook pre-/post-comando |
237238
| `pm hooks <nombre> remove <slot> "<script>"` | Eliminar un hook |
238239
| `pm hooks --all` | Listar hooks de todos los proyectos |
240+
| `pm completions <shell>` | Generar script de autocompletado (bash/zsh/fish/powershell) |
239241
| `pm rename <viejo> <nuevo>` | Renombrar un proyecto |
240242
| `pm rename <nombre> --path <ruta>` | Actualizar ruta del proyecto |
241243
| `pm refresh <nombre>` | Re-detectar tipo de proyecto y actualizar comandos |
@@ -451,9 +453,9 @@ Los proyectos se guardan en:
451453
- **CLI**`pm doctor`, `pm env`, `pm refresh`, `pm rename`, `pm update`, `pm commands add/remove`
452454
- **Runtimes** — Gradle, Maven, Node.js, .NET, Python, Rust, Go, pnpm, Bun, Yarn, Flutter, Docker
453455
- **Integraciones** — Estado Git, TTY interactivo, instaladores multi-plataforma, GitHub Actions
454-
- **Fiabilidad** — Escritura atómica, backup/recuperación, validación de directorio, integridad de descarga, 357 tests
456+
- **Fiabilidad** — Escritura atómica, backup/recuperación, validación de directorio, integridad de descarga, 402 tests
455457

456-
> Última release: **v1.5.0** (Hooks Pre-/Post-Comando) — Historial completo en [ROADMAP.md](ROADMAP.md)
458+
> Última release: **v1.6.0** (Autocompletado en Shell) — Historial completo en [ROADMAP.md](ROADMAP.md)
457459
458460
### 💡 Ideas Futuras
459461
- [ ] `pm run-all` / `pm build-all` - Ejecutar comandos en todos los proyectos

docs/es/ROADMAP.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,20 @@ Ejecuta scripts personalizados automáticamente antes o después de cualquier co
166166

167167
---
168168

169-
## v1.6.0 — Autocompletado en Shell
169+
## v1.6.0 — Autocompletado en Shell
170170

171171
### Comando `pm completions`
172-
- Generar scripts de autocompletado para bash, zsh, fish y PowerShell
173-
- `pm completions <shell>` — generar script de autocompletado para el shell especificado
174-
- Autocompletar nombres de proyecto, comandos y flags
175-
- Sin dependencias — genera scripts de shell estáticos
172+
173+
| Funcionalidad | Estado |
174+
|---------------|--------|
175+
| `pm completions bash` — generar script de autocompletado para Bash | ✅ Hecho |
176+
| `pm completions zsh` — generar script de autocompletado para Zsh | ✅ Hecho |
177+
| `pm completions fish` — generar script de autocompletado para Fish | ✅ Hecho |
178+
| `pm completions powershell` — generar script de autocompletado para PowerShell | ✅ Hecho |
179+
| Autocompletar comandos, nombres de proyecto, subcomandos y flags | ✅ Hecho |
180+
| Completado contextual (slots de hooks, claves de env vars, tipos de proyecto) | ✅ Hecho |
181+
| Callback oculto `--complete` omite banner/update para rendimiento | ✅ Hecho |
182+
| Sin dependencias — genera scripts de shell estáticos | ✅ Hecho |
176183

177184
---
178185

docs/es/User-Guide.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [Ejecución de Comandos](#-ejecución-de-comandos)
1414
- [Renombrar y Actualizar Ruta](#-renombrar-y-actualizar-ruta)
1515
- [Hooks Pre-/Post-Comando](#-hooks-prepost-comando)
16+
- [Autocompletado en Shell](#-autocompletado-en-shell)
1617
- [Gestión de Variables de Entorno](#-gestión-de-variables-de-entorno)
1718
- [Diagnósticos](#-diagnósticos)
1819
- [Ayuda y Versión](#-ayuda-y-versión)
@@ -492,6 +493,49 @@ pm hooks mi-api remove pre-build "npm run lint"
492493

493494
---
494495

496+
### 🔹 Autocompletado en Shell
497+
498+
Habilita el completado con TAB para todos los comandos de `pm`, nombres de proyecto y subcomandos.
499+
500+
#### Generar script de autocompletado
501+
```bash
502+
pm completions <shell>
503+
```
504+
505+
#### Configuración
506+
507+
**Bash** — añadir a `~/.bashrc`:
508+
```bash
509+
eval "$(pm completions bash)"
510+
```
511+
512+
**Zsh** — añadir a `~/.zshrc`:
513+
```bash
514+
eval "$(pm completions zsh)"
515+
```
516+
517+
**Fish** — guardar en directorio de completions:
518+
```bash
519+
pm completions fish > ~/.config/fish/completions/pm.fish
520+
```
521+
522+
**PowerShell** — añadir a `$PROFILE`:
523+
```powershell
524+
pm completions powershell | Out-String | Invoke-Expression
525+
```
526+
527+
#### ¿Qué se autocompleta?
528+
529+
- **Comandos principales**`pm b<TAB>``build`
530+
- **Nombres de proyecto**`pm build <TAB>` → lista todos los proyectos registrados
531+
- **Subcomandos**`pm env <TAB>``set`, `get`, `list`, `remove`, `clear`
532+
- **Flags**`pm add miproyecto <TAB>``--path`, `--type`, `--env`
533+
- **Slots de hooks**`pm hooks miproyecto add <TAB>``pre-build`, `post-run`, etc.
534+
- **Claves de variables**`pm env get miproyecto <TAB>` → lista las variables configuradas
535+
- **Nombres de shell**`pm completions <TAB>``bash`, `zsh`, `fish`, `powershell`
536+
537+
---
538+
495539
### 🔹 Gestión de Variables de Entorno
496540

497541
#### Establecer variables
@@ -1559,6 +1603,12 @@ pm rename <viejo> <nuevo> --path <ruta> # Ambos a la vez
15591603
pm refresh <nombre> # Re-detectar tipo y actualizar comandos
15601604
pm refresh --all # Refrescar todos los proyectos
15611605

1606+
# === AUTOCOMPLETADO EN SHELL ===
1607+
pm completions bash # Generar script para Bash
1608+
pm completions zsh # Generar script para Zsh
1609+
pm completions fish # Generar script para Fish
1610+
pm completions powershell # Generar script para PowerShell
1611+
15621612
# === DIAGNÓSTICOS ===
15631613
pm doctor # Verificar salud del entorno
15641614

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- Identificación del proyecto -->
99
<groupId>pm</groupId>
1010
<artifactId>projectmanager</artifactId>
11-
<version>1.5.0</version>
11+
<version>1.6.0</version>
1212
<packaging>jar</packaging>
1313

1414
<name>ProjectManager</name>

scripts/install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ProjectManager - Installation Script for Windows
22
# Works both from source (mvn clean package) and from GitHub Release download
33

4-
$jarName = "projectmanager-1.5.0.jar"
4+
$jarName = "projectmanager-1.6.0.jar"
55

66
Write-Host "=== ProjectManager Installer ===" -ForegroundColor Cyan
77
Write-Host ""

scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# ProjectManager - Installation Script for Linux/Mac
33
# Works both from source (mvn clean package) and from GitHub Release download
44

5-
JAR_NAME="projectmanager-1.5.0.jar"
5+
JAR_NAME="projectmanager-1.6.0.jar"
66

77
echo "=== ProjectManager Installer ==="
88
echo ""

src/main/java/pm/ProjectManager.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pm;
22

33
import pm.cli.OutputFormatter;
4+
import pm.completion.CompletionHandler;
5+
import pm.completion.CompletionScripts;
46
import pm.core.Project;
57
import pm.detector.ProjectType;
68
import pm.detector.ProjectTypeDetector;
@@ -68,6 +70,12 @@ public class ProjectManager {
6870
* @param args command-line arguments
6971
*/
7072
public static void main(String[] args) {
73+
// Fast path: shell completion callback (no banner, no update check)
74+
if (args.length > 0 && "--complete".equals(args[0])) {
75+
CompletionHandler.handle(args);
76+
return;
77+
}
78+
7179
printBanner();
7280

7381
// Check for updates in the background (non-blocking, 2s timeout)
@@ -95,6 +103,7 @@ public static void main(String[] args) {
95103
case "env" -> handleEnv(args);
96104
case "hooks" -> handleHooks(args);
97105
case "refresh" -> handleRefresh(args);
106+
case "completions" -> handleCompletions(args);
98107
case "update" -> UpdateChecker.performUpdate();
99108
case "doctor" -> handleDoctor();
100109
case "help", "-h", "--help" -> printHelp();
@@ -1944,6 +1953,7 @@ private static void printHelp() {
19441953
env <subcommand> <name> [options] Manage environment variables
19451954
refresh <name> Re-detect type and update commands
19461955
refresh --all Refresh all registered projects
1956+
completions <shell> Generate completion script (bash/zsh/fish/powershell)
19471957
update Update to the latest version
19481958
doctor Check environment and runtimes
19491959
help Show this help
@@ -1980,6 +1990,39 @@ Environment Variables (pm env):
19801990
""");
19811991
}
19821992

1993+
private static void handleCompletions(String[] args) {
1994+
if (args.length < 2) {
1995+
OutputFormatter.error("Shell name required.");
1996+
System.out.println("Usage: pm completions <shell>");
1997+
System.out.println("Supported shells: bash, zsh, fish, powershell");
1998+
System.out.println();
1999+
System.out.println("Setup:");
2000+
System.out.println(" Bash: eval \"$(pm completions bash)\" # add to ~/.bashrc");
2001+
System.out.println(" Zsh: eval \"$(pm completions zsh)\" # add to ~/.zshrc");
2002+
System.out.println(" Fish: pm completions fish > ~/.config/fish/completions/pm.fish");
2003+
System.out.println(" PowerShell: pm completions powershell | Out-String | Invoke-Expression # add to $PROFILE");
2004+
return;
2005+
}
2006+
2007+
String shell = args[1].toLowerCase();
2008+
String script = switch (shell) {
2009+
case "bash" -> CompletionScripts.bash();
2010+
case "zsh" -> CompletionScripts.zsh();
2011+
case "fish" -> CompletionScripts.fish();
2012+
case "powershell", "pwsh" -> CompletionScripts.powershell();
2013+
default -> null;
2014+
};
2015+
2016+
if (script == null) {
2017+
OutputFormatter.error("Unsupported shell: " + args[1]);
2018+
System.out.println("Supported: bash, zsh, fish, powershell");
2019+
return;
2020+
}
2021+
2022+
// Print raw script to stdout (no ANSI, suitable for eval/sourcing)
2023+
System.out.print(script);
2024+
}
2025+
19832026
private static void printVersion() {
19842027
System.out.println("ProjectManager " + Constants.VERSION);
19852028
System.out.println("Java " + System.getProperty("java.version"));

0 commit comments

Comments
 (0)