Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PowerShell completion generation #300

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ZettZet
Copy link

@ZettZet ZettZet commented Dec 19, 2022

I'm not an expert in PowerShell or CLI's, but this developments may help someone else complete it
Should be called like:
script completions PowerShell > $PROFILE
If I understand correctly, where PowerShell saves its configurations

Solves #253

@Holt59
Copy link

Holt59 commented Sep 29, 2023

@ZettZet I'm interested in this, why was this not merged initially? Are there blocking points? If you highlight them I can try having a look at them for this PR to be merged.

I'm not an expert in PowerShell or CLI's, but this developments may help someone else complete it
Should be called like (on Windows):
`script completions PowerShell > $HOME\Documents\PowerShell\Profile.ps1`
or (on Linux or macOS):
`script completions PowerShell > ~/.config/powershell/profile.ps1`
If I understand correctly, where PowerShell saves its configurations
@ZettZet
Copy link
Author

ZettZet commented Sep 30, 2023

@Holt59 Hi! Thanks for your attention; I appreciate it!

The two main blocking points are that this PR wasn't reviewed at all, and I'm not an expert in PowerShell or CLIs.
I may not count some specific things about cleo and/or PowerShell. Therefore, it would be nice to look at this from another perspective, perhaps by people who do have experience in those spheres.

Feel free to review, test, and modify this PR. It will be perfect to complete it!

@Secrus
Copy link
Member

Secrus commented Oct 4, 2023

From a maintainer's point of view: we are close to the 2.1 release, which will be the last 2.* release (unless something important, like a security issue happens). There is a plan for version 3.0, which will be a major overhaul of the whole library and internal workings of stuff, including completions. I left this PR open as a reference point for the future, but don't expect it to be merged "as is". Once we finalize the scope of changes for 3.0, I will revisit the Powershell completions topic and this PR as I want Cleo to include this capability.

PowerShell profiles are stored at $PROFILE path, so you can simply \
run command like this:

`<options=bold>{script_name} {command_name} PowerShell > $PROFILE</>`
Copy link
Contributor

@KotlinIsland KotlinIsland Jan 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to delete the users existing profile:

Suggested change
`<options=bold>{script_name} {command_name} PowerShell > $PROFILE</>`
`<options=bold>{script_name} {command_name} PowerShell >> $PROFILE</>`

Additionally, this directory does not exist by default, and >/>> will not create it:

👉 "a" >> $PROFILE
Out-File: Could not find a part of the path 'C:\Users\AMONGUS\Documents\PowerShell\Microsoft.PowerShell_profile.ps1'.

@@ -434,4 +434,7 @@ echo "fpath+=~/.zfunc" >> ~/.zshrc

# Fish
[program] completions fish > ~/.config/fish/completions/[program].fish

# PowerShell
[program] completions PowerShell > $PROFILE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other review note

@@ -37,7 +37,7 @@ class CompletionsCommand(Command):
)
]

SUPPORTED_SHELLS = ("bash", "zsh", "fish")
SUPPORTED_SHELLS = ("bash", "zsh", "fish", "PowerShell")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to recognize ps/pwsh as forms of PowerShell?

Additionally, would we want to ignore case for this?

> poetry completions powershell

[shell] argument must be one of bash, zsh, fish, PowerShell

$options = %(opts)s
$commands = %(cmds)s

if ($wordToComplete -notlike '--*' -and $wordToComplete -notlike "" -and """
Copy link
Contributor

@KotlinIsland KotlinIsland Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

poetry then ctrl+space doesn't show the commands, only the options:

image

%(cmds_opts)s
}

return $options | Where-Object { $_ -like "$wordToComplete*" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use CompletionResult for a richer user experience:

            New-Object -Type System.Management.Automation.CompletionResult -ArgumentList lock, lock, Method, "Locks the project dependencies."

$options = %(opts)s
$commands = %(cmds)s

if ($wordToComplete -notlike '--*' -and $wordToComplete -notlike "" -and """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

poetry cache c doesn't complete to anything

@KotlinIsland
Copy link
Contributor

I did some more work on this PR in my fork: https://github.com/KotlinIsland/cleo/tree/add-powershell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants