madsmith / bash-completion-lib

Automatically exported from code.google.com/p/bash-completion-lib
GNU General Public License v2.0
0 stars 0 forks source link

Prevent bash_completion_lib from sourcing twice #31

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.  $ . bash_completion_lib
2.  $ set -v  # Verbose
3.  $ . bash_completion_lib

What is the expected output?
The second sourcing of bash_completion_lib should comprise just a few
lines: detecting that it has already been sourced followed by a quick return.

What do you see instead?
Bash_completion_lib is sourced in its entirety for a second time.

This issue is actually addressing Launchpad (LP) # 149527 of the list of
Ubuntu-1 patches.  See also Issue 3 (i3, #3).

Original issue reported on code.google.com by fvu...@gmail.com on 28 Sep 2008 at 8:46

GoogleCodeExporter commented 8 years ago

Original comment by fvu...@gmail.com on 28 Sep 2008 at 8:48

GoogleCodeExporter commented 8 years ago
The original bash_completion of Ian Macdonald tries to prevent 
sourcing twice in two ways:

1.  By declaring `BASH_COMPLETION' and `BASH_COMPLETION_DIR' readonly.  Trying 
to
assign to them during a second run will effectively return to bash immediately
without sourcing the rest of the code:

  32 {
  33   # These declarations must go within braces in order to be able to silence
  34   # readonly variable errors.
  35   BASH_COMPLETION="${BASH_COMPLETION:-/etc/bash_completion}"
  36   BASH_COMPLETION_DIR="${BASH_COMPLETION_DIR:=/etc/bash_completion.d}"
  37 } 2>/dev/null || :
  38 readonly BASH_COMPLETION BASH_COMPLETION_DIR

2.  By sourcing a wrapper file `bash_completion.sh' containing a check for
`BASH_COMPLETION':

  3 # Check for bash (and that we haven't already been sourced).
  4 [ -z "$BASH_VERSION" -o -n "$BASH_COMPLETION" ] && return

The first method with the `readonly' trick, gave troubles with a certain 
bash-patch.
 See: https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/149527

Original comment by fvu...@gmail.com on 28 Sep 2008 at 8:55

GoogleCodeExporter commented 8 years ago
If `COMP_VERSION' is non-empty, bash_completion_lib returns immediately without
loading any completions.  Fixed in r58.

Original comment by fvu...@gmail.com on 1 Oct 2008 at 7:59