Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
## 7.0.0b3 (unreleased)


- Nothing changed yet.
- Add PowerShell support to the `completion` command: auto-detect PowerShell on Windows,
add correct profile path, create directory if missing, and fix success message to use
`. $PROFILE` instead of `source`.
[Anu13lol]


## 7.0.0b2 (2026-04-16)
Expand Down Expand Up @@ -282,3 +285,4 @@ New features:

- initital version with list templates support and bobtemplates.plone integration
[MrTango, tmassman, Gomez]

32 changes: 22 additions & 10 deletions plonecli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import importlib.metadata
import subprocess
import sys
from pathlib import Path


import click
from click_aliases import ClickAliasedGroup
Expand Down Expand Up @@ -319,7 +321,7 @@ def update(context):
@click.argument(
"shell",
required=False,
type=click.Choice(["bash", "zsh", "fish"]),
type=click.Choice(["bash", "zsh", "fish", "powershell"]),
)
@click.option("--install", is_flag=True, help="Install completion into your shell config")
def completion(shell, install):
Expand All @@ -331,14 +333,18 @@ def completion(shell, install):
import os

if shell is None:
login_shell = os.path.basename(os.environ.get("SHELL", ""))
if login_shell in ("bash", "zsh", "fish"):
shell = login_shell

if os.environ.get("PSModulePath"):
shell = "powershell"
else:
raise click.UsageError(
f"Could not detect shell (SHELL={os.environ.get('SHELL', '')!r}).\n"
"Please specify one: plonecli completion bash|zsh|fish"
)
login_shell = os.path.basename(os.environ.get("SHELL", ""))
if login_shell in ("bash", "zsh", "fish"):
shell = login_shell
else:
raise click.UsageError(
f"Could not detect shell (SHELL={os.environ.get('SHELL', '')!r}).\n"
"Please specify one: plonecli completion bash|zsh|fish"
)

env_var = "_PLONECLI_COMPLETE"
source_cmd = f"{env_var}={shell}_source plonecli"
Expand All @@ -361,13 +367,17 @@ def completion(shell, install):
"bash": os.path.expanduser("~/.bashrc"),
"zsh": os.path.expanduser("~/.zshrc"),
"fish": os.path.expanduser("~/.config/fish/completions/plonecli.fish"),
"powershell": str(Path.home() / "Documents" / "PowerShell" / "Microsoft.PowerShell_profile.ps1"),
}
rc_file = rc_files[shell]

if shell == "fish":
# Fish uses a completions directory with the script itself
os.makedirs(os.path.dirname(rc_file), exist_ok=True)
eval_line = f"env {source_cmd} | source"
elif shell == "powershell":
os.makedirs(os.path.dirname(rc_file), exist_ok=True)
eval_line = f'$env:_PLONECLI_COMPLETE = "powershell_source"\nplonecli | Out-String | Invoke-Expression'
else:
eval_line = f'eval "$({source_cmd})"'

Expand All @@ -383,8 +393,10 @@ def completion(shell, install):
f.write(f"\n# plonecli shell completion\n{eval_line}\n")

echo(f"Shell completion installed in {rc_file}", fg="green")
echo(f"Restart your shell or run: source {rc_file}", fg="green")

if shell == "powershell":
echo("Restart your shell or run: . $PROFILE", fg="green")
else:
echo(f"Restart your shell or run: source {rc_file}", fg="green")

if __name__ == "__main__":
cli()