Skip to content

[dotfiles-improvement] perf: replace echo|wc -l|tr with ZSH native line counting in ROSA functions - #539

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-wc-l-zsh-native-line-count-77f17195dfb80128
Draft

[dotfiles-improvement] perf: replace echo|wc -l|tr with ZSH native line counting in ROSA functions#539
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-wc-l-zsh-native-line-count-77f17195dfb80128

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Replace two instances of $(echo "$clusters" | wc -l | tr -d ' ') with the ZSH-native ${#${(f)clusters}} in the ROSA cluster functions.

What

echo "$clusters" | wc -l | tr -d ' ' forks two subprocesses (wc + tr) just to count the number of lines in a string.

ZSH has a built-in idiom that does this without any forks:

  • (f) splits the string on newlines
  • ${#...} counts the resulting elements
# Before (2 forks: wc + tr)
local cluster_count; cluster_count=$(echo "$clusters" | wc -l | tr -d ' ')

# After (pure ZSH, no forks)
local cluster_count=${#${(f)clusters}}

Affected files

  • zsh/functions/openshift/rosa/select-rosa-cluster.zsh — line 39
  • zsh/functions/openshift/rosa/use-rosa-sts.zsh — line 50

No behavior change

The (f) splitting + ${#} count produces the same integer result as wc -l. The tr -d ' ' was only needed to strip whitespace that wc adds on macOS — not needed with the ZSH native approach.

Generated by Dotfiles Improvement Scanner · ● 24.8M ·

…ctions

Replace $(echo "$clusters" | wc -l | tr -d ' ') with ${#${(f)clusters}}
in select-rosa-cluster.zsh and use-rosa-sts.zsh.

The (f) parameter flag splits on newlines and ${#} counts elements,
avoiding two subshell forks (wc + tr) per call.

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