mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-25 13:30:07 +00:00
Prefer ip
over ifconfig
for i/f detection.
`ifconfig`'s formatting doesn't cope well with long interface names. In these cases it will eat up the whitespace separating the name from the text "Link" in the output, which makes parsing the output problematic. e.g. `ifconfig`: wlp0s20f0u2Link encap:Ethernet HWaddr 00:AA:BB:CC:DD:EE v.s `ip`: 21: wlp0s20f0u2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc \ mq state UP group default qlen 1000 This commit swaps the order of detection inside `_p9k_prompt_net_iface_async()`, so that `ip` will be preferred. `ifconfig` is deprecated by distros in favour of `ip`, so this will often be an incredibly marginal performance boost :) NOTE: this commit does not address the problem with using `ifconfig`. I don't understand the zsh regex, so have not touched it.
This commit is contained in:
parent
8c55eb4fa3
commit
5691a418e0
1 changed files with 8 additions and 8 deletions
|
@ -5721,19 +5721,19 @@ function _p9k_prompt_net_iface_async() {
|
||||||
# netstat -inbI en0
|
# netstat -inbI en0
|
||||||
local iface ip line var
|
local iface ip line var
|
||||||
typeset -a iface2ip ips ifaces
|
typeset -a iface2ip ips ifaces
|
||||||
if (( $+commands[ifconfig] )); then
|
if (( $+commands[ip] )); then
|
||||||
for line in ${(f)"$(command ifconfig 2>/dev/null)"}; do
|
for line in ${(f)"$(command ip -4 a show 2>/dev/null)"}; do
|
||||||
if [[ $line == (#b)([^[:space:]]##):[[:space:]]##flags=([[:xdigit:]]##)'<'* ]]; then
|
if [[ $line == (#b)<->:[[:space:]]##([^:]##):[[:space:]]##\<([^\>]#)\>* ]]; then
|
||||||
[[ $match[2] == *[13579bdfBDF] ]] && iface=$match[1] || iface=
|
[[ ,$match[2], == *,UP,* ]] && iface=$match[1] || iface=
|
||||||
elif [[ -n $iface && $line == (#b)[[:space:]]##inet[[:space:]]##([0-9.]##)* ]]; then
|
elif [[ -n $iface && $line == (#b)[[:space:]]##inet[[:space:]]##([0-9.]##)* ]]; then
|
||||||
iface2ip+=($iface $match[1])
|
iface2ip+=($iface $match[1])
|
||||||
iface=
|
iface=
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
elif (( $+commands[ip] )); then
|
elif (( $+commands[ifconfig] )); then
|
||||||
for line in ${(f)"$(command ip -4 a show 2>/dev/null)"}; do
|
for line in ${(f)"$(command ifconfig 2>/dev/null)"}; do
|
||||||
if [[ $line == (#b)<->:[[:space:]]##([^:]##):[[:space:]]##\<([^\>]#)\>* ]]; then
|
if [[ $line == (#b)([^[:space:]]##):[[:space:]]##flags=([[:xdigit:]]##)'<'* ]]; then
|
||||||
[[ ,$match[2], == *,UP,* ]] && iface=$match[1] || iface=
|
[[ $match[2] == *[13579bdfBDF] ]] && iface=$match[1] || iface=
|
||||||
elif [[ -n $iface && $line == (#b)[[:space:]]##inet[[:space:]]##([0-9.]##)* ]]; then
|
elif [[ -n $iface && $line == (#b)[[:space:]]##inet[[:space:]]##([0-9.]##)* ]]; then
|
||||||
iface2ip+=($iface $match[1])
|
iface2ip+=($iface $match[1])
|
||||||
iface=
|
iface=
|
||||||
|
|
Loading…
Reference in a new issue