mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
bash: support bash completion
This commit is contained in:
parent
d9e03b7f8c
commit
f5e9879e74
6 changed files with 60 additions and 1 deletions
|
@ -30,6 +30,27 @@ in
|
|||
programs.bash = {
|
||||
enable = mkEnableOption "GNU Bourne-Again SHell";
|
||||
|
||||
enableCompletion = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Whether to enable Bash completion for all interactive Bash shells.
|
||||
|
||||
</para><para>
|
||||
|
||||
Note, if you use NixOS or nix-darwin and do not have Bash completion
|
||||
enabled in the system configuration, then make sure to add
|
||||
|
||||
<programlisting language="nix">
|
||||
environment.pathsToLink = [ "/share/bash-completion" ];
|
||||
</programlisting>
|
||||
|
||||
to your system configuration to get completion for system packages.
|
||||
Note, the legacy <filename>/etc/bash_completion.d</filename> path is
|
||||
not supported by Home Manager.
|
||||
'';
|
||||
};
|
||||
|
||||
historySize = mkOption {
|
||||
type = types.int;
|
||||
default = 10000;
|
||||
|
@ -193,6 +214,15 @@ in
|
|||
[[ -f ~/.bashrc ]] && . ~/.bashrc
|
||||
'';
|
||||
|
||||
# If completion is enabled then make sure it is sourced very early. This
|
||||
# is to avoid problems if any other initialization code attempts to set up
|
||||
# completion.
|
||||
programs.bash.initExtra = mkIf cfg.enableCompletion (mkOrder 100 ''
|
||||
if [[ ! -v BASH_COMPLETION_VERSINFO ]]; then
|
||||
. "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh"
|
||||
fi
|
||||
'');
|
||||
|
||||
home.file.".profile".source = writeBashScript "profile" ''
|
||||
. "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh"
|
||||
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
{
|
||||
programs = {
|
||||
atuin.enable = true;
|
||||
bash.enable = true;
|
||||
bash = {
|
||||
enable = true;
|
||||
enableCompletion = false;
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs = {
|
||||
|
|
23
tests/modules/programs/bash/completion.nix
Normal file
23
tests/modules/programs/bash/completion.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
programs.bash.enable = true;
|
||||
|
||||
test.stubs.bash-completion = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.bashrc
|
||||
|
||||
assertFileContains \
|
||||
home-files/.bashrc \
|
||||
'if [[ ! -v BASH_COMPLETION_VERSINFO ]]; then'
|
||||
assertFileContains \
|
||||
home-files/.bashrc \
|
||||
' . "@bash-completion@/etc/profile.d/bash_completion.sh"'
|
||||
assertFileContains \
|
||||
home-files/.bashrc \
|
||||
'fi'
|
||||
'';
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
bash-completion = ./completion.nix;
|
||||
bash-logout = ./logout.nix;
|
||||
bash-session-variables = ./session-variables.nix;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ with lib;
|
|||
config = {
|
||||
programs.bash = {
|
||||
enable = true;
|
||||
enableCompletion = false;
|
||||
|
||||
logoutExtra = ''
|
||||
clear-console
|
||||
|
|
|
@ -6,6 +6,7 @@ with lib;
|
|||
config = {
|
||||
programs.bash = {
|
||||
enable = true;
|
||||
enableCompletion = false;
|
||||
|
||||
sessionVariables = {
|
||||
V1 = "v1";
|
||||
|
|
Loading…
Reference in a new issue