mirror of
https://github.com/nix-community/home-manager.git
synced 2026-01-11 17:39:37 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user