Bash completion not working at all - what am I missing?


I was trying to get an upstream bash completion binary usable in a snap I’m working on. I tried lots of things, I read and followed trouble shooting guide Debugging tab completion, the and just couldn’t get it working.

In desperation, I created a very basic test snap, with a simple, function based, bash completion, and I still could not get it working. The completion file itself is working, if I source it both in the snap and outside it the completion starts to work.

Is there anyone that can help ? I would very much appreciate it!

The source of the test snap is here:

It should work like this:

$ tester.testing -n 
bar  boo  foo  moo  

Cheers, Just

your snap as provided works here:

$ snap install --dangerous tester_0.0.0_amd64.snap
tester 0.0.0 installed
$ tester.testing ␉␉
bin/                     .git/                    snap/                    tester_0.0.0_amd64.snap  
$ tester.testing -n ␉␉
bar  boo  foo  moo  

What might be happening is that was never fixed, and/or the equivalent for core 20/22? If you do snap list | grep ^core, what do you see? If core is not on that list, does installing core fix this issue?


Thank you so much! This has been driving me nuts, and you seem to have pointed me in the right direction.

Installing core snap does indeed solve the problem :+1:

I’m slightly confused as the the underlying reason though. I haven’t dug into /snap/snapd/15177/usr/lib/snapd/ in much detail, but bug report seems to indicate that the completion symlynk is missing if core is not installed, but in my case it was in place:

Without core installed:

$ readlink -f /usr/share/bash-completion/completions/tester.testing 

Installing a core snap that shouldn’t be required seems a overkill for completion, and is going to lead to much confusion.

Surely the implementation for this should live entirely in snapd packaging. It seems strange that it should be linked to any core snap.

Can you explain in more detail where you think the issue is @chipaca ?

Cheers, Just

That issue when I reported it was that, because the completion script runs ‘inside’ the core snap, the bash completion mechanism needs to exist in there. That means on the one hand that the bash-completion deb needs to be installed inside the coreN snap (and that does seem to have been resolved), and on the other that the script needs to be accessible (I forget if the idea was to cross-mount it in from the snapd snap, or copied in at build time). Maybe this is what’s missing? I don’t know :slight_smile:

Thanks for the extra info :+1:

So, emboldened with my success of getting completion in my test snap, I then went back to my actual snap :slight_smile:

This is a snap of the aws cli, and it comes with a binary completer utility. You just create a short bash completer snippet and that should be it.

But, I seem to be stuck again. The first problem I found, it seems that if you use a command-chain, it seems to break the completer. I tested that in my test snap, and it does break it. So for now I removed that from my actual snap. But it was not enough.

Again, I have followed the debugging guide etc, everything seems ok. Even down to the bash -x output, and the completer work if I exec into the snap like in step 5 “one last hope”.

The only thing that seems slightly off, is when I run the completer via the snap command, I just get blank lines:

snap run --command=complete amz-aws-cli 63 9 14 1 " " 'amz-aws-cli --' amz-aws-cli --
+ snap run --command=complete amz-aws-cli 63 9 14 1 ' ' 'amz-aws-cli --' amz-aws-cli --

The snap is amz-aws-cli, edge branch only atm. @chipaca if you don’t mind taking a look, are you able to see what may be wrong ?

Cheers, Just

I haven’t made time yet to reproduce your scenario in full. At a first glance I suspect your completion script isn’t being able to run the completer binary. Have you checked for that? Have you tried running the completer ‘inside’ with -x?

If you’re still stuck in a couple of days I’ll probably have some time to dig into this a bit further. Let me know.


I have tried it inside via snap run --shell, but unfortunately it does work correctly if I source bin/aws_completion.bash “inside”.

$ . $SNAP/bin/aws_completion.bash
$ amz-aws-cli s3 
< presses TAB >
cp       ls       mb       mv       presign  rb       rm       sync     website  

So it doesn’t seem to be permissions.

It’s going through a few layers of symlinks, so I just tried removing that layer and putting the target binary directly in the completer, but it still didn’t work outside the snap.

It’s really very odd. No pressure, but if you do manage find some time to help debug @chipaca I would be extremely grateful !

Cheers, Just

the behaviour of the binary completer is a little surprising. Do you have access to the source of that? I’d expect that invoking it directly, e.g.

$SNAP/bin/aws_completer amz-aws-cli '' s3

would produce the output you get when invoking it via the completer, but that is not the case. It clearly works, so I’m misunderstanding how -C works (or it works via undocumented features of bash’s programmable completion).

After figuring out that aws_completer is just some sort of frozen version of, I figured it out. There’s probably a bug in related to treatment of -C (at least), or perhaps of -F as well, in that some more environment variables need to be exported. However, there’s a workaround. Currently your completion is defined as

complete -C "${SNAP}/bin/aws_completer" amz-aws-cli.amz-aws-cli amz-aws-cli

instead, try

_amz_aws_cli_complete() {
    COMPREPLY=( $( COMP_LINE="$COMP_LINE" COMP_POINT="$COMP_POINT" "${SNAP}/bin/aws_completer" ) )
complete -F _amz_aws_cli_complete amz-aws-cli.amz-aws-cli amz-aws-cli

ETA: if you can confirm that this does indeed fix the issue, I’ll open a ticket for it.

1 Like

Hi @chipaca ,

I changed that as you suggested and published a new version, it does indeed seem to fix it ! :+1: I really appreciate you taking the time to investigate that, you have saved me quite a bit of pain there :slight_smile:

There are so many options/args for this utility, that it’s not very usable without the completion.

Now I can should be able to make the finishing touches to this snap. Thanks again.

Cheers, Just

1 Like
1 Like