From 026375da49002d4439554d04ac7f74a375e70ef5 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Thu, 4 Jan 2018 12:22:17 +0100 Subject: [PATCH] bash: use shell library --- modules/programs/bash.nix | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/programs/bash.nix b/modules/programs/bash.nix index 90ab5dd7..fa32a4be 100644 --- a/modules/programs/bash.nix +++ b/modules/programs/bash.nix @@ -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}