Skip to content

[dotfiles-improvement] perf: replace grep|cut router IP chain with ZSH parameter expansion in macos-notvscode.zsh - #553

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-router-ip-zsh-expansion-fa027b001860876d
Draft

[dotfiles-improvement] perf: replace grep|cut router IP chain with ZSH parameter expansion in macos-notvscode.zsh#553
github-actions[bot] wants to merge 1 commit into
mainfrom
fix/dotfiles-router-ip-zsh-expansion-fa027b001860876d

Conversation

@github-actions

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

Copy link
Copy Markdown
Contributor

What

Three functions in zsh/macos-notvscode.zsh extract the Wi-Fi router IP using:

# Before (spawns 2 subprocesses: grep + cut)
_router_ip=$(networksetup -getinfo Wi-Fi | grep -e "^Router" | cut -d " " -f 2)

Change

Replace cut -d " " -f 2 with ZSH nested parameter expansion:

# After (1 subprocess: grep only; cut eliminated)
_router_ip=${${$(networksetup -getinfo Wi-Fi | grep -e "^Router")}##* }

${var##* } strips the longest prefix ending in a space from the command output, extracting the IP from Router: 192.168.1.1192.168.1.1. Saves one cut fork per call.

Affected locations (3 occurrences)

Function File
set-tf-proxy zsh/macos-notvscode.zsh
set-socks-proxy zsh/macos-notvscode.zsh
get-socks-proxy zsh/macos-notvscode.zsh

No behavior change

${var##* } and cut -d " " -f 2 produce identical output for the Router: <ip> format that networksetup -getinfo Wi-Fi | grep "^Router" outputs.

Generated by Dotfiles Improvement Scanner · ● 32.5M ·

…sion

Replace `| grep -e "^Router" | cut -d " " -f 2` with ZSH nested
parameter expansion `${{${($(...))}}##* }` in three functions in
macos-notvscode.zsh.  Eliminates one fork (cut) per call; grep is still
needed to isolate the Router line from networksetup output.

Affected functions (3 occurrences):
- set-tf-proxy
- set-socks-proxy
- get-socks-proxy

No behavior change: ${var##* } strips everything up to and including the
last space, leaving the IP address — identical to cut -d ' ' -f 2 for the
'Router: <ip>' output format.

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