0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

modules/programs/bash: improve bash completion support

The new configuration.nix option 'environment.enableBashCompletion'
determines whether bash completion is automatically enabled system-wide
for all interactive shells or not. The default setting is 'off'.
This commit is contained in:
Peter Simons 2012-10-16 18:23:28 +02:00
parent 8499d7555f
commit efc104c4c8
2 changed files with 31 additions and 10 deletions

View file

@ -7,6 +7,25 @@ with pkgs.lib;
let
initBashCompletion = optionalString config.environment.enableBashCompletion ''
# Check whether we're running a version of Bash that has support for
# programmable completion. If we do, enable all modules installed in
# the system (and user profile).
if shopt -q progcomp &>/dev/null; then
. "${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh"
nullglobStatus=$(shopt -p nullglob)
shopt -s nullglob
for p in $NIX_PROFILES /run/current-system/sw; do
for m in "$p/etc/bash_completion.d/"*; do
echo enable bash completion module $m
. $m
done
done
eval "$nullglobStatus"
fi
'';
options = {
environment.shellInit = mkOption {
@ -18,6 +37,12 @@ let
type = with pkgs.lib.types; string;
};
environment.enableBashCompletion = mkOption {
default = false;
description = "Enable bash-completion for all interactive shells.";
type = with pkgs.lib.types; bool;
};
};
in
@ -38,7 +63,10 @@ in
{ # /etc/bashrc: executed every time a bash starts. Sources
# /etc/profile to ensure that the system environment is
# configured properly.
source = ./bashrc.sh;
source = pkgs.substituteAll {
src = ./bashrc.sh;
inherit initBashCompletion;
};
target = "bashrc";
}
@ -59,4 +87,5 @@ in
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
'';
environment.pathsToLink = optional config.environment.enableBashCompletion "/etc/bash_completion.d";
}