Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 338335 - app-shells/bash - bash completion loaded from profile instead of bashrc
Summary: app-shells/bash - bash completion loaded from profile instead of bashrc
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High major with 3 votes (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
: 528028 528416 (view as bug list)
Depends on:
Blocks: 527164
  Show dependency tree
 
Reported: 2010-09-22 07:23 UTC by Jaco Kroon
Modified: 2014-11-09 20:41 UTC (History)
12 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jaco Kroon 2010-09-22 07:23:41 UTC
Currently bash-completion is loaded from /etc/profile (sourcing of /etc/profile.d/*).  IMHO this should move into /etc/bash/bashrc (which shouldn't be executed ever according to the manpage, but it is being sourced from /etc/profile, and either bash is patched to source this file before .bashrc, or it should be sourced from .bashrc (there is massive disputes surrounding this, I believe Gentoo patched bash).

Currently my understanding is a login shell (such as spawned by login, or most display managers to launch your window manager) first sources /etc/profile, and then the first of .bash_profile, .bash_login or .profile.  An Interactive non-login shell sources /etc/bash/bashrc, followed by .bashrc.  A non-interactive, non-login shell won't source anything, unless it's specifically requested to do so, either via command line parameters or via BASH_ENV environment variable.

At this point it's (imho) simple to see that loading bash completion from profile is wrong, the bashrc files only gets sourced directly by bash for a non-login, interactive (such as spawned by terminal emulators) shell.  This is the ideal location to set things like bash completion up, since this won't require the user to perform a complete log-out log-in cycle to effect changes to bash completion configuration.

This would also remove the need for the checks at the top of the bash-completion.sh file (currently in /etc/profile.d).  I would suggest that /etc/bash/bashrc be rewritten to source all files in /etc/bash/bashrc.d/* (similar loop to the bottom of /etc/profile) and to then move bash-completion.sh in there rather.

As it stands I need to explicitly source /etc/profile.d/bash-completion.sh from my personal .bashrc if I want to make bash completion work (I refuse to spawn login shells just for the heck of it, which is what's currently required to get bash completion working).

At the same time I'd like to query the motivation behind the unconditional sourcing of /etc/bash/bashrc from /etc/profile when it's being invoked by bash - perhaps this should only be done for interactive shells (Yes, I am aware that there are interactivity checks in both .bashrc and /etc/bash/bashrc, I want to suggest that these should perhaps be moved to the profile variants) - this perhaps warrants a different bug report, please advise.

I'm currently using bash 4.1_p7.

Reproducible: Always




Portage 2.1.9.7 (default/linux/amd64/10.0, gcc-4.4.4, glibc-2.12.1-r1, 2.6.35.4-uls x86_64)
=================================================================
System uname: Linux-2.6.35.4-uls-x86_64-Intel-R-_Core-TM-2_CPU_U7700_@_1.33GHz-with-gentoo-2.0.1
Timestamp of tree: Thu, 16 Sep 2010 04:45:01 +0000
app-shells/bash:     4.1_p7
dev-lang/python:     2.6.5-r3, 3.1.2-r4
dev-util/cmake:      2.8.1-r2
sys-apps/baselayout: 2.0.1
sys-apps/openrc:     0.6.3
sys-apps/sandbox:    2.3-r1
sys-devel/autoconf:  2.13, 2.67
sys-devel/automake:  1.10.3, 1.11.1
sys-devel/binutils:  2.20.1-r1
sys-devel/gcc:       4.4.4-r2
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.2.10
sys-devel/make:      3.81-r2
virtual/os-headers:  2.6.35 (sys-kernel/linux-headers)
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/X11/xkb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="assume-digests distlocks fixlafiles fixpackages news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="af en_GB en"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://armadillo.local/gentoo-portage"
USE="X alsa amd64 apache2 bash-completion berkdb bluetooth branding bzip2 cli cracklib crypt cups cxx dbus dcc diskio dnsdb dri elf exiscan-acl fam gpm gzip iconv iproute2 logrotate maildir mmx modules mppe-mppc mudflap multilib mysql ncurses no-old-linux nptl nptlonly openmp pam pcre png pppd qt3support readline reflection session sox sse sse2 ssl sysfs threads unicode vim-syntax xinerama xorg zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" APACHE2_MPMS="worker" ELIBC="glibc" INPUT_DEVICES="evdev mouse keyboard synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="af en_GB en" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="intel vesa" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" 
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LANG, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Leho Kraav (:macmaN @lkraav) 2011-04-19 10:58:39 UTC
existing chain doesn't seem to be working for me either. you're supposed to be able to enable bash-completion by simply doing "eselect bashcomp enable base" etc, but this basically does not work (at least not by default) in my X setup. spawning xterms from awesome skips over /etc/profile.

if this is how it is supposed to work, perhaps a note "you *need* to do manual bash-completion if using X" would be helpful.
Comment 2 Yun Zheng Hu 2012-11-17 00:25:00 UTC
I noticed that when I perform:

  $ sudo bash

My /etc/profile.d/*.sh scripts are not loaded.

When I perform:
 
  $ sudo -i

My customizations are loaded.

Not exactly related to the bash completion issue but rather to my custom /etc/profile.d scripts. But it's the same observations that Jaco made.

I wonder if I should move my customizations into /etc/bash/bashrc or patch /etc/bash/bashrc to load /etc/profile.d/*.sh myself.

Ofcourse it would be much nicer if Gentoo has a solution for it out of the box.
(Jaco's suggestion of /etc/bash/bashrc.d/* sounds good to me)
Comment 3 SpanKY gentoo-dev 2014-11-02 18:21:44 UTC
*** Bug 528028 has been marked as a duplicate of this bug. ***
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-11-04 10:24:07 UTC
AS I pointed out in the other bug, almost all distros have the same problem, and they handle it differently:

1. Arch runs /etc/profile.d in bashrc,

2. Fedora & OpenSUSE have extra completion code in bashrc,

3. Debian asks users to load the completions manually or uncomment the code in bashrc. However, it also has the profile.d file for login shells.

As I see it, the profile.d location is completely incorrect, and is only used because distros lack any kind of bashrc.d.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-11-06 09:06:10 UTC
*** Bug 528416 has been marked as a duplicate of this bug. ***
Comment 6 Joakim Tjernlund 2014-11-06 21:44:52 UTC
Added in /etc/bash/bashrc

for sh in /etc/bash/bashrc.d/*.sh ; do
	[ -r "$sh" ] && . "$sh"
done
unset sh

Then mkdir /etc/bash/bashrc.d
Added
 ls -l /etc/bash/bashrc.d/tmp-bash-completion.sh 
lrwxrwxrwx 1 root root 34 Nov  6 22:39 /etc/bash/bashrc.d/tmp-bash-completion.sh -> ../../profile.d/bash-completion.sh

Appears to work fine

Comments?
Comment 7 Leho Kraav (:macmaN @lkraav) 2014-11-07 17:15:59 UTC
Sort of strange this doesn't have a definitive solution :)

Stuff like autojump and vcprompt are also affected. For example I run a launcher app on x2goserver, and if log in via x2goclient and launch a terminal, you don't get any goodies.


leho@server profile.d $ ls -1
autojump.bash
autojump.sh
bash-completion.sh
vcprompt.sh

What's the drawback of sourcing profile.d on non-login? All of my profile.d contents are needed all the time. Have to be careful about stuff that outputs something and breaks login processes, or something else?
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2014-11-09 20:41:47 UTC
+*bash-completion-2.1-r92 (09 Nov 2014)
+
+  09 Nov 2014; Michał Górny <mgorny@gentoo.org> +bash-completion-2.1-r92.ebuild:
+  Install initialization script to bashrc.d, bug #338335.