You are not logged in.

#1 2018-02-28 01:24:16

kryesh
Member
Registered: 2018-02-28
Posts: 2

Bash Completion Issue

Hi Everyone,

I'm having a strange issue with bash tab completions for a couple of specific commands, namely zpool and lxc
bash completion doesn't work for either of these commands until I run a couple of specific programs.

For zpool:
Bash completion will not work until i enter zfs and double tap tab to show possible entries, then i can delete everything that's entered, type in zpool and tab completions will work normally for the duration of that console session

For lxc:
Exactly the same thing happens to the lxc command except i need to type lxd instead of zfs.

Bash completion works normally for all other programs.

This is the entry in my bashrc to enable bash completions:

if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Using bash version 4.4.19

Been using arch for about 6 months now and really enjoying it so far! Thanks in advance

Offline

#2 2018-02-28 15:34:31

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Bash Completion Issue

Bash completions are activated using the completion function _completion_loader() which attempts to source /usr/share/bash-completion/completions/lxc or /usr/share/bash-completion/completions/zpool when you type in either of the respective binary names.

Some software will provide multiple command completions in one completion file, in which case symlinks should be provided for the other commands to the main completion file in order to make this work properly.

However, in the case of lxc the community/lxc package provides /usr/share/bash-completion/completions/lxc so I'm not sure why this wouldn't work.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2018-02-28 15:54:37

NoSuck
Member
Registered: 2015-03-04
Posts: 157
Website

Re: Bash Completion Issue

kryesh wrote:

For zpool:
Bash completion will not work until i enter zfs and double tap tab to show possible entries, then i can delete everything that's entered, type in zpool and tab completions will work normally for the duration of that console session

Nice find!  As Eschwartz implied, ZFS needs a completions/zpool symlink to completions/zfs.  Are you able to report the issue upstream?  Here is a temporary workaround for your bashrc:

. /usr/share/bash-completion/completions/zfs
complete -F __zpool_complete zpool

Offline

#4 2018-02-28 15:57:46

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Bash Completion Issue

Uh, https://github.com/zfsonlinux/zfs/blob/ … d/zfs#L390 already runs the second of those two commands, and if it didn't then *just* a symlink wouldn't help, but nor would tab-completing `zfs` first.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2018-02-28 16:05:28

NoSuck
Member
Registered: 2015-03-04
Posts: 157
Website

Re: Bash Completion Issue

[path] already runs the second of those two commands...

Where do you think I got it from?  In this case, it does not matter.

Offline

#6 2018-02-28 16:12:41

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Bash Completion Issue

Do you often recommend people source a script and then repeat the last few commands from the script for good luck?


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#7 2018-02-28 20:15:07

kryesh
Member
Registered: 2018-02-28
Posts: 2

Re: Bash Completion Issue

Thanks for the help guys!
That addition to my bashrc worked perfectly for the zpool command.

I had to do a little bit of tinkering for the lxc one, I'm using the lxd package from the AUR, but /usr/share/bash-completion/completions/lxc was from the original lxc package, not the lxd one. I fixed it by adding this to my bashrc

 . /usr/share/bash-completion/completions/lxd complete -F __lxc_complete lxc

What would be best way to report the issue upstream for zfs? should I just copy the text form my original post?

Thanks again for the help.

Offline

#8 2018-02-28 23:42:44

NoSuck
Member
Registered: 2015-03-04
Posts: 157
Website

Re: Bash Completion Issue

Eschwartz wrote:

Do you often recommend people source a script and then repeat the last few commands from the script for good luck?

It's one command.

Clarification just for you:  completions/zfs is not sourced until the user attempts to autocomplete the zfs command, despite zpool depending upon the last command.  Do you really think that every, single script in the completions folder is sourced at bash startup?

I am confused, as you are both knowledgeable and helpful.

kryesh wrote:

What would be best way to report the issue upstream for zfs? should I just copy the text form my original post?

Opening an issue on GitHub for glory and prestige would not be out of the question, even moreso if you mention the proposed solution:  a simple symlink from completions/zpool to completions/zfs.  Hopefully, they do not consider it a downstream issue.

Offline

#9 2018-03-01 01:47:25

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Bash Completion Issue

NoSuck wrote:
Eschwartz wrote:

Do you often recommend people source a script and then repeat the last few commands from the script for good luck?

It's one command.

`sleep 5` is also "one command", and equally pointless. I vehemently reject the notion that "it's one command" should be used as a legitimate excuse to do bizarre and pointless things that have no logical conceptualization for why they should be done. If it is wrong/unnecessary to do it, it is wrong/unnecessary no matter how insignificant the cost of doing it anyway.

Clarification just for you:  completions/zfs is not sourced until the user attempts to autocomplete the zfs command, despite zpool depending upon the last command.  Do you really think that every, single script in the completions folder is sourced at bash startup?

I am confused, as you are both knowledgeable and helpful.

You are completely missing my point.

completions/zfs is not completions/zpool, therefore it is not sourced when trying to tab-complete zpool (which runs the default `_completion_loader` completion stub function). That is the whole problem of this thread!

Sourcing that file, is in and of itself how you establish the zpool completion.

...

So, why, *after* you have done so, do you suggest redefining the zpoool completion (to what it already is)?

kryesh wrote:

What would be best way to report the issue upstream for zfs? should I just copy the text form my original post?

Opening an issue on GitHub for glory and prestige would not be out of the question, even moreso if you mention the proposed solution:  a simple symlink from completions/zpool to completions/zfs.  Hopefully, they do not consider it a downstream issue.

Do you really believe that people open a Github issue for "glory and prestige"? Funny, I usually open issues because there is something that doesn't work, that I want to work. It is by and large a rather selfish motivation, with the caveat that the best form of selfishness is the one where you acknowledge fixing something for everyone means less work down the line for you (because you do not need to fix this by hand again and again).

Do you really think that someone who wants it to work, and who knows exactly what will fix it, will for some odd reason cripple their cause by holding back information they know to be useful? What is this "moreso" you speak of?

Do you really think upstream would consider this a downstream issue? It's their installer that isn't installing something, why on earth would it be our fault? I cannot think of any project anywhere that would consider this a downstream issue as long as they bother to supply completions at all...

Do you even get the mentality of software development? These ^^ seem to be rather out of touch with general community standards for Linux, software, open-source development, hacker culture, etc. I don't know anyone who participates in these things in order to earn some mythical github points and establish a trophy wall to impress their friends at parties or something.

@kryesh

The best way to report an upstream issue is of course to give them the necessary information to understand the problem, and, since you know it, the solution. tongue

"The build system for the zfs tools installs a completion for zfs, but does not provide a symlink to zpool in order for the completion system to pick this up automatically. As a result, zpool completions are not available unless you have previously tab-completed zfs as well.

Background: this was initially discovered here: https://bbs.archlinux.org/viewtopic.php?id=234921"



...

Aside: there is really no need to enable bash completion in your bashrc, see the last line of the global /etc/bash.bashrc:

[ -r /usr/share/bash-completion/bash_completion   ] && . /usr/share/bash-completion/bash_completion

Completions are meant to "just work", you opt in to them by installing the bash-completion package. smile

Fun fact: just like you can install completions in /usr/share/bash-completion/completions/ and have them lazy-loaded only when needed, you can also install them to ~/.local/share/bash-completion/completions/ (generally for scripts etc. installed in ~/bin/ or similar). This means you can technically add your own zpool -> zfs symlink there, as a workaround that 1) does not involve modifying /usr, and 2) is lazy-loaded rather than being loaded every time you source your bashrc.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#10 2018-03-01 02:43:34

NoSuck
Member
Registered: 2015-03-04
Posts: 157
Website

Re: Bash Completion Issue

Thank you.  I was thinking in terms of aliases, e.g.:

. /usr/share/bash-completion/completions/git
__git_complete g __git_main

... and left in the extraneous line.  I apologize for being curt.  Indeed, the clarification was for me.

Do you really believe that people open a Github issue for "glory and prestige"?

No.  I believe in sarcasm that is difficult to detect.

Eschwartz wrote:

The best way to report an upstream issue is of course to give them the necessary information to understand the problem, and, since you know it, the solution.

“Do you really think that someone who wants it to work, and who knows exactly what will fix it, will for some odd reason cripple their cause by holding back information they know to be useful?”

(I agree that a symlink in ~/.local would be a good solution.)

Offline

Board footer

Powered by FluxBB