[Nix-dev] bash-interactive with support for completion

Marc Weber marco-oweber at gmx.de
Mon Sep 12 20:36:31 CEST 2011


Excerpts from Peter Simons's message of Mon Sep 12 19:49:49 +0200 2011:
> The normal bash (a.k.a. stdenv) is not affected. I would like to commit the
> patch, but before I do I wonder whether anyone sees a problem with it?

I'm too lazy to look up all details.
Summary:
- some people dislike the completion. Therefore there should be "opt-in"
- my nix2/multi-shell-support branch supports bash and zsh completion
  for several month now incloding opt-out implementation.

Because I already have a more sophisticated solution I'm likely to revert your
patch in my branches.
It was announced here: http://article.gmane.org/gmane.linux.distributions.nixos/5666/match=bash+completion
There was no feedback that time.

Marc Weber

# /etc/bash-setup-completion.sh:
# can be sourced by user to setup (unoptrusive) completion for bash

# 1) never source a completion script twice so that later profiles don't change
#    behaviour of earlier (more important ones)
# 2) allow users to opt-out from individual annoying completion scripts by
#    defining key
declare -A NIX_COMPL_SCRIPT_SOURCED

# potential problems (-rev 20179)
#  - It doesn't support filenames with spaces.
#  - It inserts a space after the filename when tab-completing in an
#    "svn" command.
#  - Many people find it annoying that tab-completion on commands like
#    "tar" only matches filenames with the "right" extension.
#  - Lluís reported bash apparently crashing on some tab completions.
# comment: Does this apply to complete.gnu-longopt or also to bash_completion?
NIX_COMPL_SCRIPT_SOURCED[complete.gnu-longopt]=1

nix_add_profile_completion(){

  # origin: bash_completion, slightly adopted
  # source script only once - allow user to use NIX_COMPL_SCRIPT_SOURCED to
  # opt out from bad scripts. If a user wants to reload all he can clear
  # NIX_COMPL_SCRIPT_SOURCED
  for s in "$1"/etc/bash_completion.d/*; do
    local base="${s/*\//}"
    [[ "${s##*/}" != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|.rpm*) ]] &&
            [ \( -f "$s" -o -h "$s" \) -a -r "$s" ] &&
            [ -z "${NIX_COMPL_SCRIPT_SOURCED[$base]}" ] &&
            { . "$s"; NIX_COMPL_SCRIPT_SOURCED[$base]=1; }
  done
}

for p in $NIX_PROFILES; do
  nix_add_profile_completion "$p"
done



More information about the nix-dev mailing list