FS#11195 - [bash-completion] needs more love

Attached to Project: Arch Linux
Opened by Xavier (shining) - Tuesday, 12 August 2008, 08:49 GMT
Last edited by Andrea Scarpino (BaSh) - Friday, 09 October 2009, 12:30 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Aaron Griffin (phrakture)
Architecture All
Severity Low
Priority Normal
Reported Version None
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:
The bash-completion package is apparently newer in the old cvs repo than in the new svn repo.
http://repos.archlinux.org/viewvc.cgi/extra/system/bash-completion/?root=extra
http://repos.archlinux.org/viewvc.cgi/bash-completion/repos/extra-i686/

Any chances the changes could be merged?
In CVS, all the unused and old files were removed, and the bash_completion.sh is much cleaner.

Also using $PS1 for detecting interactive shell is not the best way and can break in some cases.
here is a better one :
http://defindit.com/readme_files/bash_examples.html
"Using shopt -q login_shell seems to be the modern and reliable way to
detect interactive shell sessions."

So attaching a new bash_completion.sh for reflecting that change
This task depends upon

Closed by  Andrea Scarpino (BaSh)
Friday, 09 October 2009, 12:30 GMT
Reason for closing:  Fixed
Comment by Gavin Bisesi (Daenyth) - Tuesday, 12 August 2008, 18:14 GMT
A unified diff would be easier to read. diff -ruN oldfile newfile > difffile
Comment by Xavier (shining) - Tuesday, 12 August 2008, 19:12 GMT
Well I thought about posting a patch, but this script is simple enough.
Also I didn't know against which version I should diff, the newer cvs one or the older svn one.
Comment by Xavier (shining) - Tuesday, 12 August 2008, 19:40 GMT
Well, actually the only difference between cvs and svn was a little update on that bash_completion.sh file.
http://repos.archlinux.org/viewvc.cgi/extra/system/bash-completion/bash_completion.sh?root=extra&r1=1.6&r2=1.7
So I just based the diff against the svn version, and included the "remove unnecessary bash version checking" change.

Besides the shopt -q login_shell change, I made a second one too :
http://bbs.archlinux.org/viewtopic.php?pid=405760#p405760

It seems better to use $BASH_VERSION rather than $SHELL for checking that the shell is bash.
And the upstream script does it that way.
Comment by Xavier (shining) - Tuesday, 12 August 2008, 20:27 GMT
Great, when using gdm, it seems like at no point a login shell is launched, so the above patch won't work. That's pure genius.
It can be worked around by making each terminal run a login shell.

A better alternative might be to kill this bash_completion.sh script altogether, and stop worrying about it.
We could optionally add a scriptlet telling the user how to enable it : echo "source /etc/bash_completion" >> ~/.bashrc
Comment by Aaron Griffin (phrakture) - Thursday, 18 June 2009, 17:13 GMT
This change is now in testing (bash-completion 1.0)
Comment by Jim Pryor (Profjim) - Sunday, 05 July 2009, 20:02 GMT
The shopt -q login_shell test only checks for login shells, not for interactive shells. My vcN console shells are login shells, but my urxvt shells in X default to being merely interactive shells. Also, if inside a terminal I just type "bash", to get a child shell, this will again be an interactive shell and not a login shell. The current /etc/profile.d/bash_completion.sh script will ignore all of these interactive-but-not-login shells, and so I won't have any bash completion. To workaround, I need to either sourch /etc/bash_completion myself in .bashrc, as a preceding comment proposes---but that obviates the whole point of having /etc/profile.d/bash_completion.sh. Or I have to revert the bash_completion.sh script to checking [ -n "$PS1" ] or some similar test (could for example check that $- includes 'i'), instead of shopt -q login_shell. I propose we do that.
Comment by Jakub Schmidtke (sjakub) - Sunday, 06 September 2009, 18:01 GMT
Also, konsole and yakuake do not create login shells. So effectively bash_completion stopped working completely in KDE.
What is wrong with PS1 method? Maybe there is another method, that wouldn't break all Gnome and KDE installations while fixing "some cases"? ;)
Comment by Xavier (shining) - Sunday, 06 September 2009, 18:19 GMT
Well, I actually don't really understand.
isn't /etc/profile.d/bash_completion.sh only read when /etc/profile is sourced anyway ? And isn't /etc/profile only source in logging shells ?

So I guess this /etc/profile.d/bash_completion.sh is just useless and needs to be removed.

I also already wrote my opinion about this :
--------------
A better alternative might be to kill this bash_completion.sh script altogether, and stop worrying about it.
We could optionally add a scriptlet telling the user how to enable it : echo "source /etc/bash_completion" >> ~/.bashrc"
--------------

and it is also how the upstream page (http://bash-completion.alioth.debian.org/) says to enable it :
append the following to /etc/bashrc or ~/.bashrc :
--------------
you need to source it from either /etc/bashrc or ~/.bashrc. If you have bash >= 2.04, you just do it with:

# Use bash-completion, if available
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
--------------
Comment by Xavier (shining) - Sunday, 06 September 2009, 18:29 GMT
I also updated the wiki with that information :
http://wiki.archlinux.org/index.php?title=Bash&diff=75274&oldid=69317
Comment by Jim Pryor (Profjim) - Sunday, 06 September 2009, 22:25 GMT
> isn't /etc/profile.d/bash_completion.sh only read when /etc/profile is sourced anyway?
That seems to be true.

> And isn't /etc/profile only source in logging shells ?
That seems not to be true. In any case, reverting to the old $PS1-based test results in my non-login shells sourcing bash_completion.sh without its needing to be in my ~/.bashrc.

Eliminating the /etc/profile sourcing is no great hardship. It's just confusing that it should be there but be implemented in a way that ignores many terminal setups.
Comment by Aaron Griffin (phrakture) - Tuesday, 08 September 2009, 22:45 GMT
Removing /etc/profile.d/bash_completion is NOT a good idea at all. We just screwed up the implementation for non-login shells.

I will revamp this soon
Comment by Xavier (shining) - Friday, 09 October 2009, 09:09 GMT
I am quite happy with the situation now.
/etc/bash.bashrc just sources /etc/bash_completion
and in the future ( FS#16346 ), /etc/profile.bash will source /etc/bash.bashrc
so all bases will be covered, in a more elegant way (imo).

Loading...