1{ config, lib, pkgs, ... }:
2
3let
4 enable = config.programs.bash.enableCompletion;
5in
6{
7 options = {
8 programs.bash.enableCompletion = lib.mkEnableOption "Bash completion for all interactive bash shells" // {
9 default = true;
10 };
11 };
12
13 config = lib.mkIf enable {
14 programs.bash.promptPluginInit = ''
15 # Check whether we're running a version of Bash that has support for
16 # programmable completion. If we do, enable all modules installed in
17 # the system and user profile in obsolete /etc/bash_completion.d/
18 # directories. Bash loads completions in all
19 # $XDG_DATA_DIRS/bash-completion/completions/
20 # on demand, so they do not need to be sourced here.
21 if shopt -q progcomp &>/dev/null; then
22 . "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh"
23 nullglobStatus=$(shopt -p nullglob)
24 shopt -s nullglob
25 for p in $NIX_PROFILES; do
26 for m in "$p/etc/bash_completion.d/"*; do
27 . "$m"
28 done
29 done
30 eval "$nullglobStatus"
31 unset nullglobStatus p m
32 fi
33 '';
34 };
35}