Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bash completion fails if command results from alias expansion

33 views
Skip to first unread message

Tasos Papastylianou

unread,
Jun 14, 2022, 6:22:59 AM6/14/22
to
Dear bash maintainers.

I posted this at the SuperUser stackexchange forum (here: https://superuser.com/q/1725872/717607), so please see that post too if you like (especially if it generates separate conversaion, which it has not so far) but I thought I might as well ask straight from the horses mouth and submit this as a bug after all.

There are several posts online (e.g. https://superuser.com/q/436314/717607) suggesting workarounds for bash completing aliases whose commands have established completions defined.

However, in the bash manual (i.e. man bash, currently using GNU bash, version 5.0.17), section Programmable Completion, it states that:

> If there is no default compspec, bash attempts alias expansion on the command word as a final resort, and attempts to find a compspec for the command word from any successful expansion.

In other words one would have expected this to work:

function foobar () { echo "Hello from foobar"; }
function _foobar () { COMPREPLY=( foo bar baz ); } && complete -F _foobar foobar
alias foo='foobar'

Typing `foobar[TAB][TAB]` autocompletes as expected.

However, typing `foo[TAB][TAB]` does not work, and shows a default completion instead.

Given the linked posts suggesting workarounds, I don't think it's just me doing something wrong here. But then what does the quote from the bash manual actually refer to then? Am I misunderstanding the quote from the manual? Or is bash simply not doing what is says it should have been doing here? (i.e. is this simply a bug?)

I note a nearly identical question was asked in the bash bug tracker back in 2011 (with yet another nice workaround: https://groups.google.com/g/gnu.bash.bug/c/gENuqpAUTUg/m/JpHbe7KmpGgJ), but the phrasing of that question implies that this was not mentioned in the manual back then, and I haven't seen any sign of addressing this issue on the official group page since.

Also, I've checked the changelogs up to the latest version of Bash, as announced here, but it doesn't seem to me this has been addressed.

I don't know if "completion of alias expanded commands" is a good idea or not, that's a matter for debate among the maintainers (I'm of a split mind myself!); but if it *is* intended behaviour, then I'm reporting it as a bug, since it doesn't actually work as documented; and if it is not desired behaviour, then perhaps that statement about completion of alias-expanded commands should be removed from the bash man page.

Best,
Tasos

GODSWILL DUKE

unread,
Feb 15, 2023, 1:25:41 PM2/15/23
to
hello
0 new messages