Skip to content

Commit

Permalink
bash: Make sure HISTFILE's directory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCassou committed Jan 12, 2025
1 parent 2532b50 commit 50f55ee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modules/programs/bash.nix
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ in {

sessionVarsStr = config.lib.shell.exportAll cfg.sessionVariables;

historyControlStr = concatStringsSep "\n"
historyControlStr = (concatStringsSep "\n"
(mapAttrsToList (n: v: "${n}=${v}") ({
HISTFILESIZE = toString cfg.historyFileSize;
HISTSIZE = toString cfg.historySize;
Expand All @@ -190,7 +190,10 @@ in {
HISTCONTROL = concatStringsSep ":" cfg.historyControl;
} // optionalAttrs (cfg.historyIgnore != [ ]) {
HISTIGNORE = escapeShellArg (concatStringsSep ":" cfg.historyIgnore);
}));
}))) + (optionalString (cfg.historyFile != null) ''
mkdir -p "$(dirname "$HISTFILE")"
'');
in mkIf cfg.enable {
home.packages = [ cfg.package ];

Expand Down
21 changes: 21 additions & 0 deletions tests/modules/programs/bash/bash-history-control-with-file.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ config, lib, pkgs, ... }:

with lib;

{
config = {
programs.bash = {
enable = true;
historyControl = [ "erasedups" ];
historyFile = "/home/hm-user/foo/bash/history";
};

nmt.script = ''
assertFileExists home-files/.bashrc
assertFileRegex \
home-files/.bashrc \
'^mkdir -p "\$(dirname "\$HISTFILE")"'
'';
};
}
1 change: 1 addition & 0 deletions tests/modules/programs/bash/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
bash-completion = ./completion.nix;
bash-logout = ./logout.nix;
bash-session-variables = ./session-variables.nix;
bash-history-control-with-file = ./bash-history-control-with-file.nix;
}

0 comments on commit 50f55ee

Please sign in to comment.