1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

bash: use shell library

This commit is contained in:
Robert Helgesson 2018-01-04 12:22:17 +01:00
parent 58a629b02e
commit 026375da49
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -131,12 +131,6 @@ in
map (v: "shopt -s ${v}") cfg.shellOptions
);
export = n: v: "export ${n}=\"${toString v}\"";
setIfNonEmpty = n: v: optionalString (v != "") "${n}=${toString v}";
histControlStr = concatStringsSep ":" cfg.historyControl;
histIgnoreStr = concatStringsSep ":" cfg.historyIgnore;
# If Bash is the session variable setter then this is the
# attribute set of global session variables, otherwise it is an
# empty set.
@ -145,17 +139,27 @@ in
(config.home.sessionVariableSetter == "bash")
config.home.sessionVariables;
envVarsStr = concatStringsSep "\n" (
mapAttrsToList export (cfg.sessionVariables // globalEnvVars)
);
envVarsStr =
config.lib.shell.exportAll (cfg.sessionVariables // globalEnvVars);
historyControlStr =
concatStringsSep "\n" (mapAttrsToList (n: v: "${n}=${v}") (
{
HISTSIZE = toString cfg.historySize;
HISTFILESIZE = toString cfg.historyFileSize;
}
// optionalAttrs (cfg.historyControl != []) {
HISTCONTROL = concatStringsSep ":" cfg.historyControl;
}
// optionalAttrs (cfg.historyIgnore != []) {
HISTIGNORE = concatStringsSep ":" cfg.historyIgnore;
}
));
in mkIf cfg.enable {
programs.bash.bashrcExtra = ''
# Commands that should be applied only for interactive shells.
if [[ -n $PS1 ]]; then
HISTSIZE=${toString cfg.historySize}
HISTFILESIZE=${toString cfg.historyFileSize}
${setIfNonEmpty "HISTCONTROL" histControlStr}
${setIfNonEmpty "HISTIGNORE" histIgnoreStr}
${historyControlStr}
${shoptsStr}