-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
base: main
Are you sure you want to change the base?
Conversation
b3a09c8
to
dd05088
Compare
dd05088
to
bbe2875
Compare
@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
bbe2875
to
d2a179e
Compare
@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. Feel free to review, test, and modify this PR. It will be perfect to complete it! |
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</>` |
There was a problem hiding this comment.
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:
`<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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%(cmds_opts)s | ||
} | ||
|
||
return $options | Where-Object { $_ -like "$wordToComplete*" } |
There was a problem hiding this comment.
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 """ |
There was a problem hiding this comment.
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
I did some more work on this PR in my fork: https://github.com/KotlinIsland/cleo/tree/add-powershell |
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