zsh: improve histfile handling
Previously, a stateVersion check for 20.03 determined whether or not the input to `programs.zsh.history.path` would be prepended with `$HOME`. However, this was not communicated in the documentation, which stated the version check determined whether the default histfile location would be in `programs.zsh.dotDir` or `home.homeDirectory`. The current change simplifies matters and brings path handling in-line with that of the preceding work on dotDir path handling. If a relative path is provided, it is parsed as being relative to `home.homeDirectory`. Both absolute and relative paths are supported, and are cleaned before being passed to other functions. Tests have been rewritten for the new logic, with case handling for reusability. Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
21399deff2
commit
9fca491587
9 changed files with 51 additions and 65 deletions
|
|
@ -8,9 +8,8 @@ let
|
|||
cfg = config.programs.zsh;
|
||||
|
||||
inherit (lib) literalExpression mkOption types;
|
||||
inherit (config.home) stateVersion;
|
||||
|
||||
relToDotDir = file: (lib.optionalString (cfg.dotDir != null) (cfg.dotDir + "/")) + file;
|
||||
inherit (import ./lib.nix { inherit config lib; }) dotDirAbs mkAbsPathStr;
|
||||
in
|
||||
{
|
||||
options =
|
||||
|
|
@ -49,16 +48,9 @@ in
|
|||
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
default =
|
||||
if lib.versionAtLeast stateVersion "20.03" then
|
||||
"$HOME/.zsh_history"
|
||||
else
|
||||
relToDotDir ".zsh_history";
|
||||
defaultText = literalExpression ''
|
||||
"$HOME/.zsh_history" if state version ≥ 20.03,
|
||||
"$ZDOTDIR/.zsh_history" otherwise
|
||||
'';
|
||||
example = literalExpression ''"''${config.xdg.dataHome}/zsh/zsh_history"'';
|
||||
default = "${dotDirAbs}/.zsh_history";
|
||||
defaultText = "`\${config.programs.zsh.dotDir}/.zsh_history`";
|
||||
example = "`\${config.xdg.dataHome}/zsh/zsh_history`";
|
||||
description = "History file location";
|
||||
};
|
||||
|
||||
|
|
@ -188,12 +180,7 @@ in
|
|||
${lib.optionalString (
|
||||
cfg.history.ignorePatterns != [ ]
|
||||
) "HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"}"}
|
||||
${
|
||||
if lib.versionAtLeast stateVersion "20.03" then
|
||||
''HISTFILE="${cfg.history.path}"''
|
||||
else
|
||||
''HISTFILE="$HOME/${cfg.history.path}"''
|
||||
}
|
||||
HISTFILE="${mkAbsPathStr cfg.history.path}"
|
||||
mkdir -p "$(dirname "$HISTFILE")"
|
||||
|
||||
setopt HIST_FCNTL_LOCK
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue