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.
This commit is contained in:
erics118
2026-10-28 00:48:50 -04:00
committed by Austin Horstman
parent 1e3ebeb683
commit 095fef2f26
6 changed files with 6 additions and 6 deletions

View File

@@ -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) (

View File

@@ -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=(

View File

@@ -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=(

View File

@@ -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=(

View File

@@ -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=(

View File

@@ -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=(