zsh: fix lib function for env var path parsing

Allow env variables to be used and avoid mangling path.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman
2025-07-28 09:35:21 -05:00
parent 20cf285e9f
commit 938ecd797f
2 changed files with 16 additions and 2 deletions

View File

@@ -9,7 +9,7 @@ let
inherit (lib) literalExpression mkOption types;
inherit (import ./lib.nix { inherit config lib; }) dotDirAbs mkAbsPathStr;
inherit (import ./lib.nix { inherit config lib; }) dotDirAbs mkShellVarPathStr;
in
{
options =
@@ -180,7 +180,7 @@ in
${lib.optionalString (
cfg.history.ignorePatterns != [ ]
) "HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"}"}
HISTFILE="${mkAbsPathStr cfg.history.path}"
HISTFILE="${mkShellVarPathStr cfg.history.path}"
mkdir -p "$(dirname "$HISTFILE")"
setopt HIST_FCNTL_LOCK

View File

@@ -33,6 +33,20 @@ rec {
mkAbsPathStr =
pathStr: cleanPathStr ((lib.optionalString (!lib.hasPrefix "/" pathStr) "${homeDir}/") + pathStr);
# For shell variable paths like history.path that get expanded at runtime
mkShellVarPathStr =
pathStr:
let
cleanPath = lib.removeSuffix "/" pathStr;
hasShellVars = lib.hasInfix "$" cleanPath;
in
if hasShellVars then
# Does not escape shell variables, allowing them to be expanded at runtime
cleanPath
else
# For literal paths, make them absolute if needed and escape them
cleanPathStr ((lib.optionalString (!lib.hasPrefix "/" cleanPath) "${homeDir}/") + cleanPath);
dotDirAbs = mkAbsPathStr cfg.dotDir;
dotDirRel = mkRelPathStr cfg.dotDir;