Skip to content

[dotfiles-improvement] perf: replace find+sh-c exec loop with ZSH glob in view-pr-dirs (util.zsh) - #558

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-view-pr-dirs-zsh-glob-a3a128e375cd1b99
Draft

[dotfiles-improvement] perf: replace find+sh-c exec loop with ZSH glob in view-pr-dirs (util.zsh)#558
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-view-pr-dirs-zsh-glob-a3a128e375cd1b99

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Replace two find subprocess forks in view-pr-dirs (util.zsh) with ZSH-native glob qualifying and an explicit for loop.

What

view-pr-dirs used two separate find invocations:

# Before — 1 find fork to check existence
if [[ -z "$(find . -type d -maxdepth 1 -name "$1" -print -quit)" ]]; then
    echo "❌ No directories found matching pattern: $1" >&2
    return 1
fi
# Before — 1 find fork + 1 sh fork per directory
find . -type d -maxdepth 1 -name "$1" -exec sh -c 'cd "$1" || { echo "Failed to cd into $1" >&2; exit 1; }; pwd && gh pr view --web' _ {} \;
# After — pure ZSH, no forks for the check or iteration
local -a _match_dirs=( ./${~1}(N/) )
if (( ${#_match_dirs} == 0 )); then
    echo "❌ No directories found matching pattern: $1" >&2
    return 1
fi
local _dir
for _dir in "${_match_dirs[@]}"; do
    (cd "$_dir" || { echo "Failed to cd into $_dir" >&2; exit 1; }
     pwd && gh pr view --web)
done

Why

  • (N/) = nullglob (no error if no match) + directory-only qualifier — ZSH built-in, no subprocess
  • ${~1} = expand $1 as a glob pattern (safe with the existing noglob alias)
  • Eliminates 1 find fork for the guard check and 1 find + 1 sh fork per matched directory

Files Modified

  • zsh/util.zsh: view-pr-dirs function (2 → 0 find calls)

Relationship

Same pattern as PR #530 (git-utils.zsh), applied to the identical construct in util.zsh.

No behavior change

The glob (N/) is semantically equivalent to find -type d -maxdepth 1 -name. The subshell-per-directory loop preserves the cd-failure handling from the original sh -c approach.

Generated by Dotfiles Improvement Scanner · ● 37.8M ·

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