Add an option ‘environment.interactiveShellInit’
This is like ‘environment.shellInit’, but only for interactive shells.
This commit is contained in:
parent
0c021be95f
commit
2f97304833
|
@ -7,7 +7,9 @@ with pkgs.lib;
|
|||
|
||||
let
|
||||
|
||||
initBashCompletion = optionalString config.environment.enableBashCompletion ''
|
||||
cfg = config.environment;
|
||||
|
||||
initBashCompletion = optionalString cfg.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).
|
||||
|
@ -26,7 +28,7 @@ let
|
|||
'';
|
||||
|
||||
shellAliases = concatStringsSep "\n" (
|
||||
mapAttrsFlatten (k: v: "alias ${k}='${v}'") config.environment.shellAliases
|
||||
mapAttrsFlatten (k: v: "alias ${k}='${v}'") cfg.shellAliases
|
||||
);
|
||||
|
||||
options = {
|
||||
|
@ -41,24 +43,33 @@ let
|
|||
PS1="\[\033]2;\h:\u:\w\007\]$PS1"
|
||||
fi
|
||||
'';
|
||||
description = "
|
||||
Script used to initialized shell prompt.
|
||||
";
|
||||
description = ''
|
||||
Shell script code used to initialise the shell prompt.
|
||||
'';
|
||||
type = with pkgs.lib.types; string;
|
||||
};
|
||||
|
||||
environment.shellInit = mkOption {
|
||||
default = "";
|
||||
example = ''export PATH=/godi/bin/:$PATH'';
|
||||
description = "
|
||||
Script used to initialized user shell environments.
|
||||
";
|
||||
description = ''
|
||||
Shell script code called during login shell initialisation.
|
||||
'';
|
||||
type = with pkgs.lib.types; string;
|
||||
};
|
||||
|
||||
environment.interactiveShellInit = mkOption {
|
||||
default = "";
|
||||
example = ''export PATH=/godi/bin/:$PATH'';
|
||||
description = ''
|
||||
Shell script code called during interactive shell initialisation.
|
||||
'';
|
||||
type = with pkgs.lib.types; string;
|
||||
};
|
||||
|
||||
environment.enableBashCompletion = mkOption {
|
||||
default = false;
|
||||
description = "Enable bash-completion for all interactive shells.";
|
||||
description = "Enable Bash completion for all interactive shells.";
|
||||
type = with pkgs.lib.types; bool;
|
||||
};
|
||||
|
||||
|
@ -86,7 +97,7 @@ in
|
|||
source = pkgs.substituteAll {
|
||||
src = ./profile.sh;
|
||||
wrapperDir = config.security.wrapperDir;
|
||||
shellInit = config.environment.shellInit;
|
||||
inherit (cfg) shellInit;
|
||||
};
|
||||
target = "profile";
|
||||
}
|
||||
|
@ -96,8 +107,7 @@ in
|
|||
# configured properly.
|
||||
source = pkgs.substituteAll {
|
||||
src = ./bashrc.sh;
|
||||
inherit (config.environment) promptInit;
|
||||
inherit initBashCompletion shellAliases;
|
||||
inherit (cfg) interactiveShellInit;
|
||||
};
|
||||
target = "bashrc";
|
||||
}
|
||||
|
@ -115,6 +125,16 @@ in
|
|||
which = "type -P";
|
||||
};
|
||||
|
||||
environment.interactiveShellInit =
|
||||
''
|
||||
# Check the window size after every command.
|
||||
shopt -s checkwinsize
|
||||
|
||||
${cfg.promptInit}
|
||||
${initBashCompletion}
|
||||
${shellAliases}
|
||||
'';
|
||||
|
||||
system.build.binsh = pkgs.bashInteractive;
|
||||
|
||||
system.activationScripts.binsh = stringAfter [ "stdio" ]
|
||||
|
@ -122,9 +142,9 @@ in
|
|||
# Create the required /bin/sh symlink; otherwise lots of things
|
||||
# (notably the system() function) won't work.
|
||||
mkdir -m 0755 -p /bin
|
||||
ln -sfn "${config.environment.binsh}" /bin/.sh.tmp
|
||||
ln -sfn "${cfg.binsh}" /bin/.sh.tmp
|
||||
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
|
||||
'';
|
||||
|
||||
environment.pathsToLink = optional config.environment.enableBashCompletion "/etc/bash_completion.d";
|
||||
environment.pathsToLink = optional cfg.enableBashCompletion "/etc/bash_completion.d";
|
||||
}
|
||||
|
|
|
@ -16,9 +16,4 @@ fi
|
|||
# We are not always an interactive shell.
|
||||
if [ -z "$PS1" ]; then return; fi
|
||||
|
||||
# Check the window size after every command.
|
||||
shopt -s checkwinsize
|
||||
|
||||
@promptInit@
|
||||
@initBashCompletion@
|
||||
@shellAliases@
|
||||
@interactiveShellInit@
|
||||
|
|
Loading…
Reference in New Issue