Skip to content

[dotfiles-improvement] perf: replace find-subshell dir-checks with ZSH glob in git-utils.zsh - #530

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-zsh-glob-dir-check-7539dc37cd8707b8
Draft

[dotfiles-improvement] perf: replace find-subshell dir-checks with ZSH glob in git-utils.zsh#530
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-zsh-glob-dir-check-7539dc37cd8707b8

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What

Six functions in zsh/functions/git-utils.zsh use a subshell $(find ...) call just to check if any directories matching a glob pattern exist before proceeding:

# Before (spawns a subshell every call)
if [[ -z "$(find . -type d -maxdepth 1 -name "$1" -print -quit)" ]]; then
    echo "❌ No directories found matching pattern: $1" >&2
    return 1
fi

Change

Replace with ZSH-native glob qualifier (N/) — no subshell, no fork:

# After (pure ZSH, no subprocess)
local -a _match_dirs=( ./${~1}(N/) )
if (( ${#_match_dirs} == 0 )); then
    echo "❌ No directories found matching pattern: $1" >&2
    return 1
fi
  • (N/) = nullglob (no error if no match) + only match directories
  • ${~1} = expand $1 as a glob pattern (e.g. velero* stays a glob)
  • Consistent with the noglob aliases already defined at the bottom of the file

Affected functions (6 occurrences)

  • go-mod-upgrade-dirs
  • exec-dirs
  • exec-dirs-ds
  • exec-dirs-ds-echo
  • code-dirs
  • finder-dirs

No behavior change

Semantically equivalent to the find -print -quit check. The noglob aliases that call these functions already pass raw glob patterns (e.g. velero*), which ${~var} handles correctly.

Generated by Dotfiles Improvement Scanner · ● 76.4M ·

Replace 6 occurrences of find-based existence checks that spawn
subshells with ZSH-native glob qualifier pattern (no subshell):

  Before: if [[ -z "$(find . -type d -maxdepth 1 -name "$pat" -print -quit)" ]]
  After:  local -a _match_dirs=( ./${~pat}(N/) )
          if (( ${#_match_dirs} == 0 ))

The (N/) glob qualifier means N=nullglob (no error if no match),
/=directories only. Consistent with noglob aliases already in place.

Affected: go-mod-upgrade-dirs, exec-dirs, exec-dirs-ds,
exec-dirs-ds-echo, code-dirs, finder-dirs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Aug 6, 2026
Replace two find subprocess forks in view-pr-dirs (util.zsh) with
ZSH-native glob qualifying and an explicit for loop:

- $(find . -type d -maxdepth 1 -name "$1" -print -quit) -> .${~1}(N/)
  (nullglob + dir-only qualifier, no subshell)
- find -exec sh -c '...' -> explicit for _dir in ... loop with subshell
  (eliminates one find fork and one sh fork per directory)

Consistent with the same improvement in git-utils.zsh (PR #530).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants