FS#76528 - [lxd] Bash completion not working for "lxc" command

Attached to Project: Community Packages
Opened by Hugo Trassoudaine (hugotrsd) - Friday, 11 November 2022, 16:16 GMT
Last edited by Buggy McBugFace (bugbot) - Saturday, 25 November 2023, 20:04 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To George Rawlinson (rawlinsong)
Morten Linderud (Foxboron)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

[Watch out for "lxc" and "lxd" confusion]

Packaged file /usr/share/bash-completion/completions/lxd does not allow bash completion to work for "lxc" command.

When performing bash completion on "lxc" command, bash_completion script attempts to source files named "lxc", "lxc.bash", or "_lxc" under /usr/share/bash-completion/completions/ to register a completion function (see: /usr/share/bash-completion/bash_completion, body of "__load_completion" function).

Packaged file /usr/share/bash-completion/completions/lxd (from upstream https://github.com/lxc/lxd/blob/master/scripts/bash/lxd-client) supports completion for both "lxc" and "lxd.lxc" commands (nb: the latter does not exist). But being named "lxd", this file is never sourced by bash_completion, and so completion does not work for "lxc" command.

It is possible to force bash to load the completion file by starting to type "lxd" and pressing TAB to trigger the __load_completion function. Subsequent calls to "lxc" command will now support completion for the rest of the bash session.

Dependency package "lxc" installs it's own completion file for "lxc-*" commands at /usr/share/bash-completion/completions/_lxc. It should then be possible for "lxd" package to install it's own completion file at /usr/share/bash-completion/completions/lxc or /usr/share/bash-completion/completions/lxc.bash without conflicts.

Ways to solve this bug includes:
- Installing a symbolic link /usr/share/bash-completion/completions/lxc -> /usr/share/bash-completion/completions/lxd (which makes it clear that the "lxc" command is completed by the "lxd" package, while maintaining compatibility)
- Installing the file at /usr/share/bash-completion/completions/lxc instead of /usr/share/bash-completion/completions/lxd
- Documenting the behavior on Arch Wiki to inform users to create their own symbolic link (for example, in /usr/local)

NB: Users may have circumvented this bug by using shell plugins or other ways to load the completion file manually, so making this change may have unexpected side-effects for them.

Steps to reproduce:
- Open a bash prompt
- Start typing an "lxc" command, like "lxc s"
- Press TAB to attempt command completion (it shouldn't work)
- (Executing command "complete -p lxc" should return nothing)

- Clear the prompt and type "lxd" instead
- Press TAB to trigger loading of the completion file
- Clear the line and start typing an "lxc" command again, like "lxc s"
- Press TAB to attempt command completion (it should work now)
- (Executing command "complete -p lxc" should return "complete -o default -F _lxd_complete lxc")
This task depends upon

Closed by  Buggy McBugFace (bugbot)
Saturday, 25 November 2023, 20:04 GMT
Reason for closing:  Moved
Additional comments about closing:  https://gitlab.archlinux.org/archlinux/p ackaging/packages/lxd/issues/2

Loading...