Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Gentoo's way of enabling Bash completion is ugly
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
yufw
n00b
n00b


Joined: 11 Nov 2013
Posts: 57

PostPosted: Thu Apr 17, 2014 9:14 am    Post subject: Gentoo's way of enabling Bash completion is ugly Reply with quote

I think Gentoo's way of enabling Bash completion is ugly.

Basically, I want tab completion wherever possible. In Ubuntu and Arch, there is a /etc/bash_completion file in the system, the user just needs to source this file and all the completions become available. But in Gentoo, I have to enable completion by hand for every single package.

Of course you can write scripts to enable completion for all the packages at once, the problem is that there is no point to create so many symlinks in the system. Moreover, if the bash-completion package add more supported packages, the user has to enable them by hand and that is pretty distracting.

Why doesn't Gentoo also create a /etc/bash_completion file so the user can easily enable bash completion for all packages?
Back to top
View user's profile Send private message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1877
Location: Switzerland (Romandie)

PostPosted: Thu Apr 17, 2014 10:53 am    Post subject: Reply with quote

Gentoo use eselect. That way, you can have separated completion configurations for the system or each user in the system. See Bash: Tab completion. I just updated it a little bit because the example was wrong, and added a last one using eselect to globally enable all the available completions.
_________________
"Confirm You are a robot." - the singularity
Back to top
View user's profile Send private message
defer-
Tux's lil' helper
Tux's lil' helper


Joined: 11 Jun 2007
Posts: 140
Location: Finland

PostPosted: Thu Apr 17, 2014 12:28 pm    Post subject: Reply with quote

I agree. It would be much better if there was one option to enable all bash completions.
_________________
https://github.com/defer-
Back to top
View user's profile Send private message
xaviermiller
Bodhisattva
Bodhisattva


Joined: 23 Jul 2004
Posts: 8708
Location: ~Brussels - Belgique

PostPosted: Thu Apr 17, 2014 12:39 pm    Post subject: Reply with quote

something like
Code:
eselect bashcomp enable $(seq 1 9999)
?
_________________
Kind regards,
Xavier Miller
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Thu Apr 17, 2014 1:20 pm    Post subject: Reply with quote

Yeah looking at that method to enable all bash-completions, it's fragile, and a file in /etc that people could source, that is not sourced in /etc/bash/bashrc by default, would be more useful. That way the admin can comment out a specific completion for the system by default, if that's what they want to do, and only users who need it source both types, in their ~/.bashrc.

/etc/skel can be used to set that up by default if required, with the ability to turn it off just by commenting out the source of /etc/bash-completion in the subsequently-generated home file.

If we did it like that, there'd be no need for a bash-completion flag, just like there's no need for a flag to install unit-files. So long as it's not enabled by default, there's no issue.

A package installing a bash-completion file would just call an eclass function in post setup, that would add the filename to /etc/bash-completion if this is a new install and the filename is not already there, or if this is an upgrade it's not that hard to write a bash function that checks for an old version's name, and whether it's been commented out already. A bit of work, but nothing major, and much simpler than maintaining the USE flags on every package, from both sides of the equation.
Back to top
View user's profile Send private message
Maitreya
Guru
Guru


Joined: 11 Jan 2006
Posts: 441

PostPosted: Thu Apr 17, 2014 2:10 pm    Post subject: Reply with quote

I don't get it. The current setup with eselect works just fine for me.

Code:

for i in `eselect bashcomp list | awk '{print $2}'`; do eselect bashcomp enable $i; done


Also has no downsides for me like enabling what's enabled or going too fast like some other one-liners.
Back to top
View user's profile Send private message
yufw
n00b
n00b


Joined: 11 Nov 2013
Posts: 57

PostPosted: Thu Apr 17, 2014 3:01 pm    Post subject: Reply with quote

Maitreya wrote:
I don't get it. The current setup with eselect works just fine for me.

Code:

for i in `eselect bashcomp list | awk '{print $2}'`; do eselect bashcomp enable $i; done


Also has no downsides for me like enabling what's enabled or going too fast like some other one-liners.

I didn't say it does not work, but it is ugly.

Why does the user need to create a bunch of symlinks just to enable bash completion? Why would the user bother to take care of all the symlinks when a new completion is added? And is there anyone who wants completion for one command but not for another?

For me, using eselect to enable bash completion is just like hard coding or magic numbers in a program, it is very ugly.
Back to top
View user's profile Send private message
Maitreya
Guru
Guru


Joined: 11 Jan 2006
Posts: 441

PostPosted: Thu Apr 17, 2014 6:28 pm    Post subject: Reply with quote

yufw wrote:
Maitreya wrote:
I don't get it. The current setup with eselect works just fine for me.

Code:

for i in `eselect bashcomp list | awk '{print $2}'`; do eselect bashcomp enable $i; done


Also has no downsides for me like enabling what's enabled or going too fast like some other one-liners.

I didn't say it does not work, but it is ugly.

Why does the user need to create a bunch of symlinks just to enable bash completion? Why would the user bother to take care of all the symlinks when a new completion is added? And is there anyone who wants completion for one command but not for another?

For me, using eselect to enable bash completion is just like hard coding or magic numbers in a program, it is very ugly.


The "user" get's to decide to enable it or not. The USEflag "bash-completion" only adds the feature as it should.
I rather just run it when necessary than having to disable it for some users.
Why is the eselect method ugly?
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Apr 17, 2014 8:42 pm    Post subject: Reply with quote

yufw wrote:
Why does the user need to create a bunch of symlinks just to enable bash completion? Why would the user bother to take care of all the symlinks when a new completion is added? And is there anyone who wants completion for one command but not for another?

yufw ... why does the completion system require the user need do anything at all, except for perhaps defining it as enabled/disabled?

Code:
% print -rl $fpath |awk '/(site-functions|[Cc]ompletion)/'
/home/khayyam/.zsh/completions
/usr/share/zsh/site-functions
/usr/share/zsh/5.0.5/functions/Completion
/usr/share/zsh/5.0.5/functions/Completion/Base
/usr/share/zsh/5.0.5/functions/Completion/Linux
/usr/share/zsh/5.0.5/functions/Completion/Unix
/usr/share/zsh/5.0.5/functions/Completion/X
/usr/share/zsh/5.0.5/functions/Completion/Zsh
% autoload compinit

Anyhow, having some method of enabling/disabling specific completions seems to me the correct way of handling it, particularly as (looking at a /etc/bash_completion elsewhere) these are all sourced functions (rather than 'autoloaded' as in zsh).

That said ... as this is shell initialisation there is no reason you can't use a similar /etc/bash_completion in $HOME and omit using eselect altogether.

best ... khay
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Fri Apr 18, 2014 9:09 am    Post subject: Reply with quote

Actually, I never understood, too, why the gentoo developers decided for this user-inconvenient way
Quite a while ago (when I did not know that zsh is a much better interactive shell than bash), I had solved the problem by symlinking one directory to the other:
I forgot the paths meanwhile, but eselect just creates symlinks in some directory. So if you just remove that directory and replace it by a symlink to the directory with the completion files, you do not need to enable anything ('though you better avoid calling "eselect bashcomp" from now on - if somebody did not care in writing it, it might not recognize the situation and replace the file by a symlink).
Quote:
Anyhow, having some method of enabling/disabling specific completions seems to me the correct way of handling it

Yes, but the default should be to enable everything - you can then unset a function later on if you do not want it; disabling something should be very exceptional: If, in general, you want completion, I can hardly think of a reason why you would not want completion for a particular command. It must really be something exceptional (a very badly written completion with a time or security issue)...
Quote:
these are all sourced functions (rather than 'autoloaded'

bash does not know the concept of an autoloaded function. Moreover, it saves almost no time anyway since the fille is opened once in any case, and the memory is not really relevant nowadays. The only disadvantage is that it pollutes the user's namespace, but unfortunately this is the same with zsh (as sooin as sufficiently many functions had to be loaded). At least zsh has a pseudo-convention for these functions (to start them all with _), hence they have a "separate namespace" in a mild sense.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Apr 18, 2014 12:42 pm    Post subject: Reply with quote

mv wrote:
khayyam wrote:
Anyhow, having some method of enabling/disabling specific completions seems to me the correct way of handling it

Yes, but the default should be to enable everything - you can then unset a function later on if you do not want it; disabling something should be very exceptional: If, in general, you want completion, I can hardly think of a reason why you would not want completion for a particular command. It must really be something exceptional (a very badly written completion with a time or security issue)...

mv ... well, I was comparing to the /etc/bash_completion method (Ubuntu, Arch) that yufw suggests as better than symlinks. Anyhow, if I were to do this (in zsh) I would do the following:

Code:
for d in $fpath ; do
  f=( $d/*~*~(N.x:t) )
  (( ${#f} )) && autoload $f
done

... and then set/unset the executable bit on $f. Seems easier than managing symlinks and one chmod would be enough to enable all completions.

mv wrote:
khayyam wrote:
these are all sourced functions (rather than 'autoloaded'

bash does not know the concept of an autoloaded function. Moreover, it saves almost no time anyway since the fille is opened once in any case, and the memory is not really relevant nowadays.

Its becomes more relevant as the completion system grows ... in my (admittedly limited) experience of bash-completion shell initialisation is slower than zsh (but perhaps zcompile also plays some part in this). As for memory being irrelevant, that could be argued ...

mv wrote:
The only disadvantage is that it pollutes the user's namespace, but unfortunately this is the same with zsh (as sooin as sufficiently many functions had to be loaded). At least zsh has a pseudo-convention for these functions (to start them all with _), hence they have a "separate namespace" in a mild sense.

Indeed, but besides this zsh offers styles and tags to configure the completion system.

best ... khay
Back to top
View user's profile Send private message
TomWij
Retired Dev
Retired Dev


Joined: 04 Jul 2012
Posts: 1553

PostPosted: Sat Apr 19, 2014 8:41 am    Post subject: Reply with quote

Yeah, there are quite some bugs (https://bugs.gentoo.org/buglist.cgi?quicksearch=bash-completion) and the previous QA team has asked me to mask the newer revision;
nowadays the newer revision is no longer in the Portage tree, it is being worked in an (local?) overlay according to https://bugs.gentoo.org/show_bug.cgi?id=477380
Back to top
View user's profile Send private message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1877
Location: Switzerland (Romandie)

PostPosted: Sat Apr 19, 2014 9:24 am    Post subject: Reply with quote

Personally, I don't care what the method to enable/disable completion is as long it work and is simple to use. I also thing, as many packages have a completion related USE flag, that when enabled the global default must be on.

As sys admin, I also think the eselect model have at least one obvious advantage on gentoo: it will not force you to use etc-update each time a software update add or remove something in the completion stuffs. It just work without my intervention, and that's a really nice feature 8)
_________________
"Confirm You are a robot." - the singularity
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Mon Apr 21, 2014 4:07 pm    Post subject: Reply with quote

Dominique_71 wrote:
Personally, I don't care what the method to enable/disable completion is as long it work and is simple to use.

Agreed.
Quote:
I also think as many packages have a completion related USE flag, that when enabled the global default must be on.

The problem is requiring a use-flag in the first place, for what could only ever be a bash scriptlet file. It makes no sense.

The only situation where it could make sense is if the package had to compile in additional code to support bash-completion. That's a real stretch though, and much less of a real problem than systemd integration leading to unportable code, by design.
Quote:
As sys admin, I also think the eselect model have at least one obvious advantage on gentoo: it will not force you to use etc-update each time a software update add or remove something in the completion stuffs. It just work without my intervention, and that's a really nice feature

I'd prefer taking a leaf out of prior art, and just having a directory of files, with chmod -x to disable as khayyam outlined. No-one's saying we can't tweak the bash-completion loaded in profile; simply that it shouldn't be up to the user to run a loop checking what's available, and running a specific command for each, which is hardly convenient. Even if you add eselect --all, the current setup is fragile, ugly and inflexible, when there is a much better method, which would also allow a trivial eselect module.

Yes, we can add that at our side, but isn't that what a distribution is supposed to be for? If not, there'd be no call for an eselect module in the first place, afaict.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Mon Apr 21, 2014 4:46 pm    Post subject: Reply with quote

I'd much rather have a "only pay for what you use" setup. And by that I mean the useflag should install things on-by-default, and the gazillion files bash-completion installs by default need to be taken outside and shot.

I'm really not going to need apt-get *and* rpm completion on a gentoo machine any time this decade.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Mon Apr 21, 2014 6:10 pm    Post subject: Reply with quote

Usually, if a package has USE=bash-completion, it is a bug or a very old package which has not yet been updated:
Gentoo maintainers have agreed that installing such a tiny file should not invoke a useflag.
In fact, the code for useflag in the gentoo tree takes up more space than the space which is saved by not installing the file.
The only exception, as steveL said, is if the package would change something else (e.g. compile an additional tool) if bash-completion is enabled. To be honest, I doubt that such a case exists, i.e. if you see a current package with USE=bash-completion, this is probably a bug.

USE-flags should not change the default which is set up with eselect: eselect exists for a reason and not to be overridden accidentally.

Quote:
I'm really not going to need apt-get *and* rpm completion on a gentoo machine any time this decade.

But what do you loose when you get it? By omitting it you save less than a ms when you start an interactive shell - which for an interactive shell you certainly do no even realize, and you save a few bytes of ram which is also practically nothing.
In fact, zsh does not even have a mechanism to avoid loading completions. In the mv overlay there is a zsh and a zsh-completion which makes use of a USE-expand variable to possibly disable completoins for various classes (e.g. android google haskell AID BSD Cygwin Darwin Debian ...) which most users won't need. I am not sure whether these few bytes are worth the effort.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Mon Apr 21, 2014 6:32 pm    Post subject: Reply with quote

steveL wrote:
I'd prefer taking a leaf out of prior art, and just having a directory of files, with chmod -x to disable as khayyam outlined.

steve ... the above wouldn't work as bash doesn't support glob qualifiers (14.8.7). To do this eselect-bashcomp would need to install some file (probably to /etc/profile.d/) that calls find and makes a list of the files with +x and then have the shell load them ... and of course none of this will happen if the user has their own ~/.profile, or hasn't set theirs up to do the same.

Ant P. wrote:
I'm really not going to need apt-get *and* rpm completion on a gentoo machine any time this decade.

In ten years from now bash will have completion 'styles' (though no doubt they'll be called 'tyles' or 'styes' ... to keep to their usual NIH naming convention) and you'll be able to do the following ...

Code:
# ignore completion functions for non-existant commands
zstyle ':completion:*:functions' ignored-patterns '_*'

... but why wait ... just use this simple bashrc :)

Code:
exec /bin/zsh

best ... khay
Back to top
View user's profile Send private message
jimmij
Tux's lil' helper
Tux's lil' helper


Joined: 02 Dec 2008
Posts: 139

PostPosted: Tue Apr 22, 2014 11:04 am    Post subject: Reply with quote

mv wrote:
Usually, if a package has USE=bash-completion, it is a bug or a very old package which has not yet been updated [...] if you see a current package with USE=bash-completion, this is probably a bug.

Does the same apply to zsh-completion?
Because the only package in my world which use this flag is eix.
_________________
Vanitas vanitatum et omnia vanitas.
Libera temet ex inferis.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6747

PostPosted: Tue Apr 22, 2014 11:59 am    Post subject: Reply with quote

jimmij wrote:
Does the same apply to zsh-completion?
Because the only package in my world which use this flag is eix.

Yes, this applies also to zsh-completion, and I think new versions of eix are fixed according to the new policy. (At the time when eix introduced zsh-completion, this was long before the policy was discussed, and zsh-completion was a global use flag which was used by many packages.)

BTW: eix is one of the very few packages where I see a reason why somebody might want to avoid the completion: It is rather slow if used with auto-fu.zsh (which calls the completion function for every keypress).
I played around with zstyle to configure that the most time-consuming tasks are skipped and e.g. only options are completed (and no package names), but it does not work as expected: I do not know whether something in zstyle is broken or whether eix just uses it in a wrong way. If you are a zsh guru, help would be appreciated :wink:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum