help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How come source bash_completion cannot be early


From: Greg Wooledge
Subject: Re: How come source bash_completion cannot be early
Date: Thu, 31 Aug 2023 07:30:07 -0400

On Thu, Aug 31, 2023 at 12:31:49PM +0700, Budi wrote:
> How come code to source bash_completion cannot work as early as when
> the /etc/profile is initialzed/ run, as sourcing is put inside the
> file

See below.

> while sourcing is put inside the ~/.bashrc file, it's too later and
> very inefficient for user often or always need to re-initialize it

Why is it "too late"?  Too late for what?

Programmable completions are normally sourced from ~/.bashrc for three
reasons:

1) Other shells besides bash read /etc/profile, and sourcing a bash-
   specific file from a non-bash shell could be very bad.  (Of course,
   you could add a check for BASH_VERSION or something around it.)

2) Not everyone WANTS programmable completions, and there may be other
   users besides you on this computer.

3) If you DO want them, you probably want them on ALL your shells, not
   just your login shell.

A typical local user will login once, either on the text console, or
via a graphical Display Manager.  Then they'll start X (if they logged
in on the console), or they'll be dropped directly into an X or Wayland
session (DM).  Then they'll run a terminal (xterm, or something similar),
and inside that terminal, they'll have a NON-LOGIN shell.[1]

It's that non-login shell that they'll actually use, and in which they
will want to have their programmable completions.

That non-login shell does NOT read /etc/profile, so putting the per-shell
triggers (functions, aliases, set, shopt, source) there would not help.

Of course, you may not be a local user.  If you only access this systems
via ssh (or something similar), you may always be in a login shell.  In
that case, you may never have learned the difference between login and
non-login shells, or why there are so many different dot files.  The
same applies to console-only users, largely.

If only there were a way we could KNOW how you login and how you use
your system.  Gee, how could that be possible?  That would require
something... like... a transfer of information between people.  What
would we even call that?  "Communication"?  Wow, what a novel concept
that would be.

So:  What PROBLEM are you encountering?  Did you TRY moving
the source line to the other file?  Did it work?  Did it fail?  Did you
learn anything?

Even more fundamentally:  What operating system are you using?  How do
you login?  Do you end up in a graphical environment?  If so, which one?
How do you get to a command shell?  Are your programmable completions
working as expected in that shell?  What ISN'T working?  Do you own
this computer?  Are you the only user on this computer?  Do you have
access to "root" on this computer?


[1] Some people launch all their xterms with the -ls option which causes
    them to run a login shell.  Other terminals may have an analogous
    option.  This is a horrible legacy configuration that became popular
    in environments where the end users are not very sophisticated --
    college students, for example, or Mac users.

    So, if you're one of these "xterm -ls" type people, you may think
    that everything I've said is wrong.  And some of it is wrong, for you,
    and your particular configuration.

    If you're NOT one of these people, well then, everything I said
    should be mostly correct.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]