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 completion troubleshooting guide #4821

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

Conversation

bebound
Copy link
Contributor

@bebound bebound commented Nov 29, 2024

Currently, there is no guide for tab completion for Linux.

Related issue: Azure/azure-cli#30441

Copy link
Contributor

Learn Build status updates of commit 51cd805:

✅ Validation status: passed

File Status Preview URL Details
.gitignore ✅Succeeded
docs-ref-conceptual/includes/cli-install-linux-apt.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-dnf.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-tdnf.md ✅Succeeded View
docs-ref-conceptual/includes/linux-completion.md ✅Succeeded View
docs-ref-conceptual/install-azure-cli-macos.md ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Learn Build status updates of commit 6acc66f:

✅ Validation status: passed

File Status Preview URL Details
.gitignore ✅Succeeded
docs-ref-conceptual/includes/cli-install-linux-apt.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-dnf.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-tdnf.md ✅Succeeded View
docs-ref-conceptual/includes/linux-completion.md ✅Succeeded View
docs-ref-conceptual/install-azure-cli-macos.md ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Learn Build status updates of commit 2bb564a:

✅ Validation status: passed

File Status Preview URL Details
.gitignore ✅Succeeded
docs-ref-conceptual/includes/cli-install-linux-apt.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-dnf.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-tdnf.md ✅Succeeded View
docs-ref-conceptual/includes/linux-completion.md ✅Succeeded View
docs-ref-conceptual/install-azure-cli-macos.md ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

.gitignore Outdated
@@ -6,6 +6,7 @@ _themes/
_themes.MSDN.Modern/
_themes.VS.Modern/
.vscode
.idea
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest not adding this as this repo is never meant to be opened by idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use Idea to open every Git repo.
Well, I'll remove this change.

@bebound
Copy link
Contributor Author

bebound commented Dec 2, 2024

@dbradish-microsoft Could you please help review this pr?

Copy link
Contributor

Learn Build status updates of commit 08a68f1:

✅ Validation status: passed

File Status Preview URL Details
docs-ref-conceptual/includes/cli-install-linux-apt.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-dnf.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-tdnf.md ✅Succeeded View
docs-ref-conceptual/includes/linux-completion.md ✅Succeeded View
docs-ref-conceptual/install-azure-cli-macos.md ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

Copy link
Contributor

Learn Build status updates of commit 08a68f1:

✅ Validation status: passed

File Status Preview URL Details
docs-ref-conceptual/includes/cli-install-linux-apt.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-dnf.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-tdnf.md ✅Succeeded View
docs-ref-conceptual/includes/linux-completion.md ✅Succeeded View
docs-ref-conceptual/install-azure-cli-macos.md ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

Copy link
Collaborator

@dbradish-microsoft dbradish-microsoft left a comment

Choose a reason for hiding this comment

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

The TDNF doc doesn't have a Troubleshooting H2, so one needs to be added.

@bebound
Copy link
Contributor Author

bebound commented Dec 16, 2024

@dbradish-microsoft Thanks for the review, I've committed the suggestions.

Copy link
Contributor

Learn Build status updates of commit 4822727:

✅ Validation status: passed

File Status Preview URL Details
docs-ref-conceptual/includes/cli-install-linux-apt.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-dnf.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-tdnf.md ✅Succeeded View
docs-ref-conceptual/includes/linux-completion.md ✅Succeeded View
docs-ref-conceptual/install-azure-cli-macos.md ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

@jiasli
Copy link
Member

jiasli commented Jan 3, 2025

Currently, there is guide for tab completion for Linux.

Missing a "no"?

Copy link
Contributor

Learn Build status updates of commit dd4ed0a:

✅ Validation status: passed

File Status Preview URL Details
docs-ref-conceptual/includes/cli-install-linux-apt.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-dnf.md ✅Succeeded View
docs-ref-conceptual/includes/cli-install-linux-tdnf.md ✅Succeeded View
docs-ref-conceptual/includes/linux-completion.md ✅Succeeded View
docs-ref-conceptual/install-azure-cli-macos.md ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

For Zsh users, add the following two lines in your `~/.zshrc` file, then save and reload your Zsh profile:

```zsh
autoload -U +X bashcompinit && bashcompinit
Copy link
Member

@jiasli jiasli Jan 6, 2025

Choose a reason for hiding this comment

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

Will this command automatically load /etc/bash_completion.d/azure-cli?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, bashcompinit only emulates the complete function in bash.

The function bashcompinit provides compatibility with bash’s programmable completion system. When run it will define the functions, compgen and complete which correspond to the bash builtins with the same names. It will then be possible to use completion specifications and functions written for bash.
--- https://zsh.sourceforge.io/Doc/Release/Completion-System.html

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@bebound bebound Feb 6, 2025

Choose a reason for hiding this comment

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

Source of this command: https://stackoverflow.com/a/49277309/2251785

With the -U flag, alias expansion is suppressed when the function is loaded.

The flag +X attempts to load each name as an autoloaded function, but does not execute it. The exit status is zero (success) if the function was not previously defined and a definition for it was found. This does not replace any existing definition of the function. The exit status is nonzero (failure) if the function was already defined or when no definition was found. In the latter case the function remains undefined and marked for autoloading. If ksh-style autoloading is enabled, the function created will contain the contents of the file plus a call to the function itself appended to it, thus giving normal ksh autoloading behaviour on the first call to the function. If the -m flag is also given each name is treated as a pattern and all functions already marked for autoload that match the pattern are loaded.

The flags -z and -k mark the function to be autoloaded using the zsh or ksh style, as if the option KSH_AUTOLOAD were unset or were set, respectively.

https://man.archlinux.org/man/zshall.1.en#autoload

Copy link
Member

@jiasli jiasli Feb 6, 2025

Choose a reason for hiding this comment

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

The AWS document https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-completion.html uses

autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit

Our document for MacOS https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-macos#completion-isnt-working also only uses

autoload bashcompinit && bashcompinit

Copy link
Contributor Author

@bebound bebound Feb 8, 2025

Choose a reason for hiding this comment

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

What is the purpose and source of this autoload -U +X bashcompinit command?

Found some explanation on it:

After reading these docs. It seems -Uz is always the right option for autoload.

"-Uz"? Yes, that is "the right thing"[tm] almost always, so I won't discuss it here. See the manual for details. --- http://bewatermyfriend.org/p/2012/003/

For +X, it returns nonzero exit code if the function is defined. It saves some time if the .zshrc has multiple autoload bashcompinit.

Also, compinit is also needed for completion.

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.

3 participants