mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 07:13:23 +01: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:
parent
8499d7555f
commit
efc104c4c8
2 changed files with 31 additions and 10 deletions
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -27,15 +27,7 @@ if test "$TERM" = "xterm"; then
|
|||
PS1="\[\033]2;\h:\u:\w\007\]$PS1"
|
||||
fi
|
||||
|
||||
# Check whether we're running a version of Bash that has support for
|
||||
# programmable completion. If we do, and if the current user has
|
||||
# installed the package 'bash-completion' in her $HOME/.nix-profile,
|
||||
# then completion is enabled automatically.
|
||||
if [ -f "$HOME/.nix-profile/etc/profile.d/bash_completion.sh" ]; then
|
||||
if shopt -q progcomp &>/dev/null; then
|
||||
. "$HOME/.nix-profile/etc/profile.d/bash_completion.sh"
|
||||
fi
|
||||
fi
|
||||
@initBashCompletion@
|
||||
|
||||
# Some aliases.
|
||||
alias ls="ls --color=tty"
|
||||
|
|
Loading…
Reference in a new issue