git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell
@ 2012-03-28 20:27 Kerrick Staley
  2012-03-28 22:17 ` Junio C Hamano
  2012-03-28 23:06 ` Jonathan Nieder
  0 siblings, 2 replies; 8+ messages in thread
From: Kerrick Staley @ 2012-03-28 20:27 UTC (permalink / raw)
  To: git

The __git_ps1 function is defined in same script that defines Git's
tab completions (contrib/completion/git-completion.bash). Since
bash-completion loads completions on-the-fly in newer versions, the
__git_ps1 function isn't immediately available in a new shell. How
should this be handled? Should users just source git-completion.bash
before they redefine $PS1?

-Kerrick Staley

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell
  2012-03-28 20:27 bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell Kerrick Staley
@ 2012-03-28 22:17 ` Junio C Hamano
  2012-03-29  5:57   ` Jeff King
  2012-03-28 23:06 ` Jonathan Nieder
  1 sibling, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2012-03-28 22:17 UTC (permalink / raw)
  To: Kerrick Staley; +Cc: git

Kerrick Staley <mail@kerrickstaley.com> writes:

> The __git_ps1 function is defined in same script that defines Git's
> tab completions (contrib/completion/git-completion.bash). Since
> bash-completion loads completions on-the-fly in newer versions, the
> __git_ps1 function isn't immediately available in a new shell. How
> should this be handled? Should users just source git-completion.bash
> before they redefine $PS1?

Sorry, I don't quite get it.  "newer verions" of what?

To me, completion scripts have always been to be dot-sourced early, making
sure inclusion happen before PS1 is used.  Did we change anything recently
to break it????

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell
  2012-03-28 20:27 bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell Kerrick Staley
  2012-03-28 22:17 ` Junio C Hamano
@ 2012-03-28 23:06 ` Jonathan Nieder
  2012-03-29  0:00   ` Kerrick Staley
  1 sibling, 1 reply; 8+ messages in thread
From: Jonathan Nieder @ 2012-03-28 23:06 UTC (permalink / raw)
  To: Kerrick Staley; +Cc: git, bash-completion-devel

Kerrick Staley wrote:

>                                                           Since
> bash-completion loads completions on-the-fly in newer versions, the
> __git_ps1 function isn't immediately available in a new shell. How
> should this be handled? Should users just source git-completion.bash
> before they redefine $PS1?

Yes, I think so.  Do the release notes for version 2.0 of the
/etc/bash_completion wrapper script mention this change?

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell
  2012-03-28 23:06 ` Jonathan Nieder
@ 2012-03-29  0:00   ` Kerrick Staley
  2012-03-29  5:49     ` Jeff King
  2012-04-07 13:01     ` Felipe Contreras
  0 siblings, 2 replies; 8+ messages in thread
From: Kerrick Staley @ 2012-03-29  0:00 UTC (permalink / raw)
  To: Jonathan Nieder, gitster; +Cc: bash-completion-devel, git

On Wed, Mar 28, 2012 at 5:17 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Sorry, I don't quite get it.  "newer verions" of what?
>
> To me, completion scripts have always been to be dot-sourced early, making
> sure inclusion happen before PS1 is used.  Did we change anything recently
> to break it????

bash-completion 1.99 (still a "beta", but Arch Linux now ships it)
will automatically source the git-completion.bash script when you type
git <tab>. The script is no longer sourced when you first open a
shell.

There are two main ways to fix this:
1) define __git_ps1 (and friends) in a different script, which will
get installed in /etc/profile.d (this is the "proper way")
2) require that git-completion.bash always be loaded in the beginning
instead of on-the-fly (which is how it works now now)

I can submit a patch implementing option (1) if needed.

This is a very minor issue, but some recommendation from upstream
would be nice so that distros know how to handle this.

On Wed, Mar 28, 2012 at 6:06 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Yes, I think so.  Do the release notes for version 2.0 of the
> /etc/bash_completion wrapper script mention this change?

I'm not sure, but the feature is definitely there. The branch
implementing this feature has been merged into the project's master
(see http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=commit;h=b377dc5de84913b69efa325590e9d0bb97d02128).

-Kerrick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell
  2012-03-29  0:00   ` Kerrick Staley
@ 2012-03-29  5:49     ` Jeff King
  2012-04-07 13:01     ` Felipe Contreras
  1 sibling, 0 replies; 8+ messages in thread
From: Jeff King @ 2012-03-29  5:49 UTC (permalink / raw)
  To: Kerrick Staley; +Cc: Jonathan Nieder, gitster, git, bash-completion-devel

On Wed, Mar 28, 2012 at 07:00:35PM -0500, Kerrick Staley wrote:

> bash-completion 1.99 (still a "beta", but Arch Linux now ships it)
> will automatically source the git-completion.bash script when you type
> git <tab>. The script is no longer sourced when you first open a
> shell.
> 
> There are two main ways to fix this:
> 1) define __git_ps1 (and friends) in a different script, which will
> get installed in /etc/profile.d (this is the "proper way")
> 2) require that git-completion.bash always be loaded in the beginning
> instead of on-the-fly (which is how it works now now)

I would much rather see (1). There is a very good reason for
bash-completion doing dynamic loading, which is that loading all of the
completions made shell startup horribly slow. We should do our part to
help keep startup fast by splitting the dynamically-loadable bits from
the must-be-loaded-at-start bits.

-Peff

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell
  2012-03-28 22:17 ` Junio C Hamano
@ 2012-03-29  5:57   ` Jeff King
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff King @ 2012-03-29  5:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Kerrick Staley, git

On Wed, Mar 28, 2012 at 03:17:13PM -0700, Junio C Hamano wrote:

> Kerrick Staley <mail@kerrickstaley.com> writes:
> 
> > The __git_ps1 function is defined in same script that defines Git's
> > tab completions (contrib/completion/git-completion.bash). Since
> > bash-completion loads completions on-the-fly in newer versions, the
> > __git_ps1 function isn't immediately available in a new shell. How
> > should this be handled? Should users just source git-completion.bash
> > before they redefine $PS1?
> 
> Sorry, I don't quite get it.  "newer verions" of what?
> 
> To me, completion scripts have always been to be dot-sourced early, making
> sure inclusion happen before PS1 is used.  Did we change anything recently
> to break it????

No, it is not us. The bash-completion project used to look in something
like /etc/bash_completions.d and load everything at shell startup.
Packagers could then drop our git-completion file there, and everything
just worked.

But it made starting the shell very slow, as you loaded completions for
commands that you were unlikely to ever run. Newer versions of
bash-completions load as little as possible on startup. When you first
try to tab-complete "git <tab>", _then_ it looks for a "git" file and
loads it on the fly.

So people who put ". /path/to/git-completion.bash" have nothing to worry
about. Everything will work as normal. People who depend on dropping
the file somewhere that bash-completion can find it (or who use a
package which does so) will find that they do not have __git_ps1 at
shell startup with newer versions of bash-completion. Those people will
need to start sourcing the file themselves (or possibly bash-completion
could do it, but it really feels like it is not their responsibility, as
the prompt functions have nothing to do with completion).

We can help them out by breaking the file apart into "must be loaded at
startup" and "can be loaded dynamically" bits, so they don't end up
loading more than they need to.

-Peff

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell
  2012-03-29  0:00   ` Kerrick Staley
  2012-03-29  5:49     ` Jeff King
@ 2012-04-07 13:01     ` Felipe Contreras
  2012-04-07 13:47       ` Jonathan Nieder
  1 sibling, 1 reply; 8+ messages in thread
From: Felipe Contreras @ 2012-04-07 13:01 UTC (permalink / raw)
  To: Kerrick Staley; +Cc: Jonathan Nieder, bash-completion-devel, git, gitster

On Thu, Mar 29, 2012 at 3:00 AM, Kerrick Staley <mail@kerrickstaley.com> wrote:
> 1) define __git_ps1 (and friends) in a different script, which will
> get installed in /etc/profile.d (this is the "proper way")

I prefer this because it's useful for zsh as well; not everybody uses
the bash completion in zsh. I believe somebody already proposed this
because of this reason. FWIW I named the script git-prompt.sh on my
side.

Cheers.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell
  2012-04-07 13:01     ` Felipe Contreras
@ 2012-04-07 13:47       ` Jonathan Nieder
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Nieder @ 2012-04-07 13:47 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: Kerrick Staley, gitster, git, bash-completion-devel

Felipe Contreras wrote:
> On Thu, Mar 29, 2012 at 3:00 AM, Kerrick Staley <mail@kerrickstaley.com> wrote:

>> 1) define __git_ps1 (and friends) in a different script, which will
>> get installed in /etc/profile.d (this is the "proper way")
>
> I prefer this because it's useful for zsh as well

Sounds good to me.  In fact, I imagine you'll find no one it does not
sound good to.  Please feel free to make it so.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-04-07 13:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-28 20:27 bash-completion now loads completions dynamically, so __git_ps1 is not defined when you open a shell Kerrick Staley
2012-03-28 22:17 ` Junio C Hamano
2012-03-29  5:57   ` Jeff King
2012-03-28 23:06 ` Jonathan Nieder
2012-03-29  0:00   ` Kerrick Staley
2012-03-29  5:49     ` Jeff King
2012-04-07 13:01     ` Felipe Contreras
2012-04-07 13:47       ` Jonathan Nieder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).