From 095fef2f265c3c0da4fe315efba8f8a04495ab34 Mon Sep 17 00:00:00 2001 From: erics118 <52634785+erics118@users.noreply.github.com> Date: Wed, 28 Oct 2026 00:48:50 -0400 Subject: [PATCH] zsh: skip mkdir history directory when it exists Every interactive shell ran `mkdir -p "$(dirname "$HISTFILE")"`, which forks twice, even though the directory almost always exists. It costs ~10ms on macOS 27. We now test if the directory exists first and use zsh's `:h` modifier instead of dirname, so the most of the time no processes are started. The directory is still created when missing. --- modules/programs/zsh/history.nix | 2 +- tests/modules/programs/fabric-ai/zshrc | 2 +- tests/modules/programs/zsh/aliases.nix | 2 +- .../programs/zsh/history-substring-search-expected.zshrc | 2 +- tests/modules/programs/zsh/smart-formatting-expected.zshrc | 2 +- tests/modules/programs/zsh/zshrc-content-priorities.nix | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/programs/zsh/history.nix b/modules/programs/zsh/history.nix index 19972c6aae..743bb192de 100644 --- a/modules/programs/zsh/history.nix +++ b/modules/programs/zsh/history.nix @@ -218,7 +218,7 @@ in cfg.history.ignorePatterns != [ ] ) "HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"}"} HISTFILE="${mkShellVarPathStr cfg.history.path}" - mkdir -p "$(dirname "$HISTFILE")" + [[ -d ''${HISTFILE:h} ]] || mkdir -p "''${HISTFILE:h}" '') (lib.mkIf (cfg.historySubstringSearch.enable or false) ( diff --git a/tests/modules/programs/fabric-ai/zshrc b/tests/modules/programs/fabric-ai/zshrc index d567f77ebc..68f7d74e8e 100644 --- a/tests/modules/programs/fabric-ai/zshrc +++ b/tests/modules/programs/fabric-ai/zshrc @@ -12,7 +12,7 @@ HISTSIZE="10000" SAVEHIST="10000" HISTFILE="/home/hm-user/.zsh_history" -mkdir -p "$(dirname "$HISTFILE")" +[[ -d ${HISTFILE:h} ]] || mkdir -p "${HISTFILE:h}" # Set shell options set_opts=( diff --git a/tests/modules/programs/zsh/aliases.nix b/tests/modules/programs/zsh/aliases.nix index b1456cf4fe..f7d9647e5e 100644 --- a/tests/modules/programs/zsh/aliases.nix +++ b/tests/modules/programs/zsh/aliases.nix @@ -29,7 +29,7 @@ SAVEHIST="10000" HISTFILE="/home/hm-user/.zsh_history" - mkdir -p "$(dirname "$HISTFILE")" + [[ -d ''${HISTFILE:h} ]] || mkdir -p "''${HISTFILE:h}" # Set shell options set_opts=( diff --git a/tests/modules/programs/zsh/history-substring-search-expected.zshrc b/tests/modules/programs/zsh/history-substring-search-expected.zshrc index 7b23401067..0692af4a07 100644 --- a/tests/modules/programs/zsh/history-substring-search-expected.zshrc +++ b/tests/modules/programs/zsh/history-substring-search-expected.zshrc @@ -12,7 +12,7 @@ HISTSIZE="10000" SAVEHIST="10000" HISTFILE="/home/hm-user/.zsh_history" -mkdir -p "$(dirname "$HISTFILE")" +[[ -d ${HISTFILE:h} ]] || mkdir -p "${HISTFILE:h}" # Set shell options set_opts=( diff --git a/tests/modules/programs/zsh/smart-formatting-expected.zshrc b/tests/modules/programs/zsh/smart-formatting-expected.zshrc index 931c685ffe..33540b7a89 100644 --- a/tests/modules/programs/zsh/smart-formatting-expected.zshrc +++ b/tests/modules/programs/zsh/smart-formatting-expected.zshrc @@ -12,7 +12,7 @@ HISTSIZE="50000" SAVEHIST="50000" HISTFILE="/home/hm-user/.zsh_history" -mkdir -p "$(dirname "$HISTFILE")" +[[ -d ${HISTFILE:h} ]] || mkdir -p "${HISTFILE:h}" # Set shell options set_opts=( diff --git a/tests/modules/programs/zsh/zshrc-content-priorities.nix b/tests/modules/programs/zsh/zshrc-content-priorities.nix index f160c77138..e92f5783f1 100644 --- a/tests/modules/programs/zsh/zshrc-content-priorities.nix +++ b/tests/modules/programs/zsh/zshrc-content-priorities.nix @@ -69,7 +69,7 @@ SAVEHIST="10000" HISTFILE="/home/hm-user/.zsh_history" - mkdir -p "$(dirname "$HISTFILE")" + [[ -d ''${HISTFILE:h} ]] || mkdir -p "''${HISTFILE:h}" # Set shell options set_opts=(