[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
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three functions in
zsh/macos-notvscode.zshextract the Wi-Fi router IP using:Change
Replace
cut -d " " -f 2with ZSH nested parameter expansion:${var##* }strips the longest prefix ending in a space from the command output, extracting the IP fromRouter: 192.168.1.1→192.168.1.1. Saves onecutfork per call.Affected locations (3 occurrences)
set-tf-proxyzsh/macos-notvscode.zshset-socks-proxyzsh/macos-notvscode.zshget-socks-proxyzsh/macos-notvscode.zshNo behavior change
${var##* }andcut -d " " -f 2produce identical output for theRouter: <ip>format thatnetworksetup -getinfo Wi-Fi | grep "^Router"outputs.