Another try on this.
And a patch against bash-completion 2.1-4 as in Jessie.

If the concept seems acceptable I could do that on git master +
the documentation bits.

About XDG_DATA_HOME, I'm still not comfortable about it being the only
choice (even if symlinks are possible).

This comes to the fact that;
- for a command-line based application I feel something between
  "strange" and "overkill" (eg: AFAIK bash itself does not treat
  ~/$XDG_DATA_HOME/.bashrc)
  
- Whatever is the path of this "bash_completion" directory, it could
  very well store completion's configuration (through environment
  variable, like COMP_SAMBA_SCAN & co). Thus ~/XDG_CONFIG_HOME could be
  valid option too (unless things are split between
  ~/$XDG_DATA_HOME/bash_completion/completions and
  ~/$XDG_CONFIG_HOME/bash_completion ...)

One pro of a "standardized" path over a user-defined only path is the
ability of unprivileged 3rd-party tools to install completions
automatically or install them for a specific user (inside
$XDG_DATA_HOME).
This has the side-effect of potentially breaking user's
bash-completion too without the said user even having touched its
configuration himself. The use of a $BASH_COMPLETION_USER_DIR variable
avoids that.

If we ever use a fallback-construct iterating over several user-defined
directories (what the attached patch does), maybe considering only one
unique environment variable as a list of colon-separated paths would
be simpler on the bash-completion side and avoid assumptions about
user's $HOME tree/management.
--- /usr/share/bash-completion/bash_completion	2014-03-22 17:59:12.000000000 -0300
+++ /usr/share/bash-completion/bash_completion.new	2015-02-13 00:35:39.953138563 -0300
@@ -1943,12 +1943,16 @@
 # set up dynamic completion loading
 _completion_loader()
 {
-    local compfile=./completions
-    [[ $BASH_SOURCE == */* ]] && compfile="${BASH_SOURCE%/*}/completions"
-    compfile+="/${1##*/}"
+    local def_compdir=./completions
+    [[ $BASH_SOURCE == */* ]] && def_compdir="${BASH_SOURCE%/*}/completions"
+    local all_compdir=( "$BASH_COMPLETION_USER_DIR/completions" "$XDG_DATA_HOME/bash-completion/completions" "$HOME/.local/share/bash-completion/completions" $def_compdir )
+    local compdir
+    for compdir in ${all_compdir[*]}; do
+	compfile="${compdir}/${1##*/}"
 
-    # Avoid trying to source dirs; https://bugzilla.redhat.com/903540
-    [[ -f "$compfile" ]] && . "$compfile" &>/dev/null && return 124
+	# Avoid trying to source dirs; https://bugzilla.redhat.com/903540
+	[[ -f "$compfile" ]] && . "$compfile" &>/dev/null && return 124
+    done
 
     # Need to define *something*, otherwise there will be no completion at all.
     complete -F _minimal "$1" && return 124
_______________________________________________
Bash-completion-devel mailing list
Bash-completion-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel

Reply via email to