Azure / azure-cli

Azure Command-Line Interface
MIT License
4.01k stars 2.98k forks source link

Support autocompletion in command line PowerShell console. #2324

Closed chaliy closed 1 year ago

chaliy commented 7 years ago

I am big fun of new Azure CLI 2.0. However my working console is Powershell, is there any chance to get autocomplete for Powershell?

There are many examples of successful integrations to Powershell:

troydai commented 7 years ago

Hi @chaliy thank you for the advice. We will take a look at this during our planning.

Since essentially a PowerShell console is just a Windows command line window, I'll update the subject to reflect the fact that you actually ask for autocompletion in command line window.

In the meantime, since we have autocompletion for bash you can use it on Windows through cygwin or Ubuntu subsystem in Windows 10.

chaliy commented 7 years ago

@troydai thanks for response. I believe that PowerShell autocompletion has nothing to do with "windows command line window". In PowerShell you actually alter TabExpansion function to react on your commands. After it's done it will work for any PowerShell environment (PowerShell ISE, PowerShell in Windows Console, etc). It will not affect CMD.

Another good example of tabexpansion implementation is Posh-GIT - https://github.com/dahlbyk/posh-git/blob/master/src/GitTabExpansion.ps1

troydai commented 7 years ago

I see what you're saying. I'll change the subject line.

tomasaschan commented 6 years ago

Is there any news on this? I'd love to see this supported as well!

tjprescott commented 6 years ago

Powershell is not actively supported by the CLI team, so there are currently no plans for this.

ChristianSauer commented 6 years ago

Very sad, since PowerShell is the shell to use in windows. Honestly, I think it's kind of hilarious, since even docker (a native linux tool!) has better powershell support than a core microsoft product.

troydai commented 6 years ago

@ChristianSauer thank you for the comments. The Azure CLI 2.0 is designed to be a bash oriented. Its tab completion is supported in bash on Windows as well as cywin and mingw. On the other hand Azure PowerShell CLI is optimized to be used in the PowerShell command line environment, under which it also supports tab completion. The essense of this issue, however, is to support tab completion for Azure CLI 2.0 (a bash-oriented tool) in PowerShell environment.

kgopi1 commented 6 years ago

Azure CLI is much easy to use rather than Azure Powershell , As we used the PowerShell ISE for script editor , it would be nice if you include teh auto completion azure CLI ... As Docker and other tools supporting , Hope it not big deal for Azure CLI to provide that feature ..

lafe commented 6 years ago

@troydai This might be true. However, the documentation and hints jump back and forth from using the CLI tools to PowerShell. I am currently working with Docker and Kubernetes and the Docker commands in the help were in PowerShell and the Kubernetes connection is given in Azure CLI in the Azure Portal. So both tools are required and it would be great to have similar support in both tools.

Leon99 commented 5 years ago

The Azure CLI 2.0 is designed to be a bash oriented. Its tab completion is supported in bash on Windows as well as cywin and mingw. On the other hand Azure PowerShell CLI is optimized to be used in the PowerShell command line environment, under which it also supports tab completion.

The problem here is that Azure PowerShell CLI only supports a subset of what az can do. Any plans on having one toolset that works equally fine on all both platforms?

tjprescott commented 5 years ago

At this time we have no plans to add support for Powershell tab completion. The CLI was not designed with Powershell as an intended shell, and while it does work, people generally run into more issues with special characters and so forth. Since the target shell for Azure CLI is bash, our priority is on fully supporting tab completion there, and even in that regard there is much to do.

For other shells, az interactive is currently the only supported mechanism for tab completion.

That being said, if anyone in the community would like to contribute a PR that adds tab completion support for Powershell, we would gladly review it for inclusion.

chriskuech commented 5 years ago

Powershell is not actively supported by the CLI team, so there are currently no plans for this.

I just spent an hour trying to get WSL to integrate like a native terminal with unsatisfactory results. Please fully support Windows. Many of the Azure docs only feature az and lack parity with Azure PowerShell.

I have also yet to get tab completion working on WSL bash.

rroman81 commented 5 years ago

This looks like a sizable undertaking but granted that a large number of PowerShell based users do use Azure CLI, this would be immensely helpful. Anyone wants to start posh-az module? :)

thomaslevesque commented 5 years ago

Powershell is not actively supported by the CLI team, so there are currently no plans for this.

That's irrelevant. Look at the dotnet CLI: it doesn't "actively support" PowerShell, but it has a "complete" command, which is shell-agnostic. This command can then be used to integrate with any shell (PowerShell, bash or zsh for instance). Look here for details: https://docs.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete#powershell

winstonhenke-work commented 5 years ago

+1 for using Azure CLI in PowerShell and wanting it to be fully supported. We are a Dotnet shop so PowerShell is everywhere for us.

heaths commented 5 years ago

As @thomaslevesque pointed out, the dotnet CLI supports any shell that supports expansions. That same documentation has instructions that enable it for bash and zsh, as common examples.

The big benefit to you is that - with a little introspection - you don't have to maintain it have users install separate expansion files. Users set up completion once and are done no matter how many times they update the az CLI. You have no need to keep those files up to date.

Seems like a win-win.

yonzhan commented 4 years ago

add to S165.

jiasli commented 4 years ago

Azure CLI uses Python's argcomplete for auto-completion. As mentioned in https://github.com/kislyuk/argcomplete/issues/166, currently there is no good implementation for Python apps to achieve auto-completion in PowerShell terminal.

wqoq commented 3 years ago

You might want to remove the following highlighted sentence from this documentation: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli#run-the-azure-cli

Run the Azure CLI You can now run the Azure CLI with the az command from either Windows Command Prompt or PowerShell. PowerShell offers some tab completion features not available from Windows Command Prompt. To sign in, run the az login command.

Although that sentence is true by itself, in that context it implies you can use tab completion in Powershell with Azure CLI. I definitely don't read that and get the sense that there are "no plans to add support for Powershell tab completion"—quite the opposite in fact.

jiasli commented 2 years ago

@wqoq, the sentence "PowerShell offers some tab completion features not available from Windows Command Prompt." has been removed by https://github.com/MicrosoftDocs/azure-docs-cli/pull/2801.

wqoq commented 2 years ago

@wqoq, the sentence "PowerShell offers some tab completion features not available from Windows Command Prompt." has been removed by MicrosoftDocs/azure-docs-cli#2801.

Disappointing outcome, but thanks. At least that should reduce some confusion for the next people that encounter that documentation.

jiasli commented 2 years ago

@wqoq, I totally understand, but currently there is hardly any good implementation for local exe command's auto-complete in PowerShell. 😥

jiasli commented 2 years ago

For what it's worth, you may use F8 key in PowerShell to bring back a command from the history (you typed before). I always found this helpful.

image

See https://docs.microsoft.com/en-us/powershell/module/psreadline/about/about_psreadline?view=powershell-7.2#historysearchbackward

szymonos commented 2 years ago

@wqoq, I totally understand, but currently there is hardly any good implementation for local exe command's auto-complete in PowerShell. 😥

There is autocomplete for git, kubectl, how it is different for az? It is quite annoying that third party companies can and do support PowerShell while Microsoft itself don't.

rbleattler commented 2 years ago

Azure CLI uses Python's argcomplete for auto-completion. As mentioned in kislyuk/argcomplete#166, currently there is no good implementation for Python apps to achieve auto-completion in PowerShell terminal.

Cool cool -- why on earth is the azure cli written in python when it doesn't have clean support for the Windows native shell? Sorry this just sounds lazy... If the dotnet cli can do this (snippet below), someone can do it in a python based app...

Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
  param($commandName, $wordToComplete, $cursorPosition)
  dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
    [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
  }
}
aviita commented 2 years ago

For what it's worth, you may use F8 key in PowerShell to bring back a command from the history (you typed before). I always found this helpful.

image

See https://docs.microsoft.com/en-us/powershell/module/psreadline/about/about_psreadline?view=powershell-7.2#historysearchbackward

Well for that you just must setup up and down arrow history lookup with PSReadLine module:

Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Had this once auto configured in bash and never have understood the plain up arrow previous command being the default ever since. As who would want the previous command if there is already something written over there.

Sorry if that was off topic, but it does make the lacking tab completion bit more manageable, though would still love to have proper tab completion for commands. Nothing breaks the flow of writing command than having to Ctrl+C and type az --help (or starting to google the documentation)...

aviita commented 2 years ago

Would think bit of consultation from @gvanrossum from Microsoft would help fix that for Azure CLI, though maybe he's priorities lie elsewhere: image

Starts to make sense why there is need for both Azure PowerShell and this one if this issue cannot be fixed. Was just ranting when starting AZ-104 certification study that why on earth are both Azure CLI and Azure Powershell needed if Az cli can work on both bash and powershell...

So I guess the winner is still undecided, but maybe should go back to Azure Powershell my self over this although I do like the syntax of Azure CLI better.

gvanrossum commented 2 years ago

Owners of this issue might want to lock it down. I'm unsubscribing.

rbleattler commented 1 year ago

So I guess the winner is still undecided, but maybe should go back to Azure Powershell my self over this although I do like the syntax of Azure CLI better.

If the preference towards the az cli is syntax you could try wrapping it using Set-Alias

gvanrossum commented 1 year ago

Looks like a spammer is active here. :-(

aviita commented 1 year ago

So I guess the winner is still undecided, but maybe should go back to Azure Powershell my self over this although I do like the syntax of Azure CLI better.

If the preference towards the az cli is syntax you could try wrapping it using Set-Alias

I do not think that is the same thing at all. Azure powershell has totally different command structure, so cannot alias between the two.

aviita commented 1 year ago

And maybe I was totally out of line referencing Mr. Guido Van Rossum here. So my apologies. Though won't tag him to spam any further.

aviita commented 1 year ago

@wqoq, I totally understand, but currently there is hardly any good implementation for local exe command's auto-complete in PowerShell. 😥

How about this python-prompt-toolkit library for implementing autocomplete on python?

Read in stackoverflow it being used for IronPython, so would think it is properly maintained.

Didjacome commented 1 year ago

Good afternoon everybody

I hope you are well

this auto complete option will be released for powershell 7?

bebound commented 1 year ago

@Didjacome Yes, #24752 supports PowerShell 7.

Didjacome commented 1 year ago

thanks @bebound i am waiting for the PRs request

bebound commented 1 year ago

The feature has been released. See Enable Tab Completion on PowerShell

TechnicallyJoe commented 1 year ago

The feature has been released. See Enable Tab Completion on PowerShell

It works for me. Although its quite slow compared to other auto completion options but i'll take anything i can get!

rbleattler commented 1 year ago

Awesome, love to see it!