Skip to content

[dotfiles-improvement] perf: replace grep -q here-string with ZSH built-in pattern matching - #533

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-grep-to-zsh-pattern-8edef7726b509c3d
Draft

[dotfiles-improvement] perf: replace grep -q here-string with ZSH built-in pattern matching#533
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-grep-to-zsh-pattern-8edef7726b509c3d

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What

Five places across two files use grep -q "literal" <<< "$var" to test if a variable contains a substring:

# Before (spawns a subshell + forks grep each call)
grep -q "Plugable USBC-6950U" <<< "$usb_info" &&
grep -q "TS4" <<< "$usb_info" &&

Change

Replace with ZSH's built-in glob pattern matching:

# After (pure ZSH, no subprocess)
[[ "$usb_info" == *"Plugable USBC-6950U"* ]] &&
[[ "$usb_info" == *TS4* ]] &&

[[ var == *pattern* ]] is a ZSH built-in that does substring matching without spawning a subshell or forking grep. Semantically equivalent for literal string checks.

Affected locations (5 occurrences)

  • zsh/macos-notvscode.zshis-at-home (2 occurrences), is-displaylink-connected (2 occurrences)
  • zsh/aliases/go.zshgolangci-lint-with-retry (1 occurrence)

No behavior change

Literal substring matching is identical between grep -q and [[ == *pattern* ]].

Generated by Dotfiles Improvement Scanner · ● 69.2M ·

Replace `grep -q "literal" <<< "\$var"` with `[[ "\$var" == *pattern* ]]`
in macos-notvscode.zsh (4 occurrences) and aliases/go.zsh (1 occurrence).

ZSH built-in string matching requires no subshell or external process,
making these checks faster and more portable.

Affected functions:
- is-at-home (macos-notvscode.zsh): 2 occurrences
- is-displaylink-connected (macos-notvscode.zsh): 2 occurrences
- golangci-lint-with-retry (aliases/go.zsh): 1 occurrence

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