mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-22 04:10:07 +00:00
fix nordvpn; it was broken by the latest upstream update (#1590)
This commit is contained in:
parent
0ce9df66d2
commit
ed45177e19
1 changed files with 49 additions and 29 deletions
|
@ -4695,34 +4695,60 @@ typeset -gra __p9k_nordvpn_tag=(
|
||||||
)
|
)
|
||||||
|
|
||||||
function _p9k_fetch_nordvpn_status() {
|
function _p9k_fetch_nordvpn_status() {
|
||||||
setopt err_return
|
setopt err_return no_multi_byte
|
||||||
local REPLY
|
local REPLY
|
||||||
zsocket $1
|
zsocket /run/nordvpn/nordvpnd.sock
|
||||||
local -i fd=$REPLY
|
local -i fd=REPLY
|
||||||
{
|
{
|
||||||
>&$fd echo -nE - $'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n\0\0\0\4\1\0\0\0\0\0\0N\1\4\0\0\0\1\203\206E\221bA\226\223\325\\k\337\31i=LnH\323j?A\223\266\243y\270\303\fYmLT{$\357]R.\203\223\257_\213\35u\320b\r&=LMedz\212\232\312\310\264\307`+\210K\203@\2te\206M\2035\5\261\37\0\0\5\0\1\0\0\0\1\0\0\0\0\0'
|
print -nu $fd 'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n\0\0\0\4\1\0\0\0\0\0\0;\1\4\0\0\0\1\203\206E\213b\270\327\2762\322z\230\326j\246A\206\240\344\35\23\235\t_\213\35u\320b\r&=LMedz\212\232\312\310\264\307`+\262\332\340@\2te\206M\2035\5\261\37\0\0\5\0\1\0\0\0\1\0\0\0\0\0\0\0\25\1\4\0\0\0\3\203\206E\215b\270\327\2762\322z\230\334\221\246\324\177\302\301\300\277\0\0\5\0\1\0\0\0\3\0\0\0\0\0'
|
||||||
local tag len val
|
local val
|
||||||
local -i n
|
local -i len n wire tag
|
||||||
{
|
{
|
||||||
IFS='' read -t 0.25 -r tag
|
IFS='' read -t 0.25 -r val
|
||||||
tag=$'\n'
|
val=$'\n'
|
||||||
while true; do
|
while true; do
|
||||||
tag=$((#tag))
|
tag=$((#val))
|
||||||
|
wire='tag & 7'
|
||||||
(( (tag >>= 3) && tag <= $#__p9k_nordvpn_tag )) || break
|
(( (tag >>= 3) && tag <= $#__p9k_nordvpn_tag )) || break
|
||||||
tag=$__p9k_nordvpn_tag[tag]
|
if (( wire == 0 )); then
|
||||||
[[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
|
# varint
|
||||||
sysread -s 1 -t 0.25 len
|
sysread -s 1 -t 0.25 val
|
||||||
len=$((#len))
|
n=$((#val))
|
||||||
val=
|
(( n < 128 )) || break # bail on multi-byte varints
|
||||||
while true; do
|
if (( tag == 2 )); then
|
||||||
(( len )) || break
|
# P9K_NORDVPN_TECHNOLOGY
|
||||||
|
case $n in
|
||||||
|
1) typeset -g P9K_NORDVPN_TECHNOLOGY=OPENVPN;;
|
||||||
|
2) typeset -g P9K_NORDVPN_TECHNOLOGY=NORDLYNX;;
|
||||||
|
3) typeset -g P9K_NORDVPN_TECHNOLOGY=SKYLARK;;
|
||||||
|
*) typeset -g P9K_NORDVPN_TECHNOLOGY=UNKNOWN;;
|
||||||
|
esac
|
||||||
|
elif (( tag == 3 )); then
|
||||||
|
# P9K_NORDVPN_PROTOCOL
|
||||||
|
case $n in
|
||||||
|
1) typeset -g P9K_NORDVPN_PROTOCOL=UDP;;
|
||||||
|
2) typeset -g P9K_NORDVPN_PROTOCOL=TCP;;
|
||||||
|
*) typeset -g P9K_NORDVPN_PROTOCOL=UNKNOWN;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# length-delimited
|
||||||
|
(( wire == 2 )) || break
|
||||||
|
(( tag != 2 && tag != 3 )) || break
|
||||||
[[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
|
[[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
|
||||||
sysread -c n -s $len -t 0.25 'val[$#val+1]'
|
sysread -s 1 -t 0.25 val
|
||||||
len+=-n
|
len=$((#val))
|
||||||
done
|
val=
|
||||||
typeset -g $tag=$val
|
while (( $#val < len )); do
|
||||||
|
[[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
|
||||||
|
sysread -s $(( len - $#val )) -t 0.25 'val[$#val+1]'
|
||||||
|
done
|
||||||
|
typeset -g $__p9k_nordvpn_tag[tag]=$val
|
||||||
|
fi
|
||||||
[[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
|
[[ -t $fd ]] || true # https://www.zsh.org/mla/workers/2020/msg00207.html
|
||||||
sysread -s 1 -t 0.25 tag
|
sysread -s 1 -t 0.25 val
|
||||||
done
|
done
|
||||||
} <&$fd
|
} <&$fd
|
||||||
} always {
|
} always {
|
||||||
|
@ -4773,14 +4799,8 @@ function _p9k_fetch_nordvpn_status() {
|
||||||
# POWERLEVEL9K_NORDVPN_CONNECTING_BACKGROUND=cyan
|
# POWERLEVEL9K_NORDVPN_CONNECTING_BACKGROUND=cyan
|
||||||
function prompt_nordvpn() {
|
function prompt_nordvpn() {
|
||||||
unset $__p9k_nordvpn_tag P9K_NORDVPN_COUNTRY_CODE
|
unset $__p9k_nordvpn_tag P9K_NORDVPN_COUNTRY_CODE
|
||||||
if [[ -e /run/nordvpn/nordvpnd.sock ]]; then
|
[[ -e /run/nordvpn/nordvpnd.sock ]] || return
|
||||||
sock=/run/nordvpn/nordvpnd.sock
|
_p9k_fetch_nordvpn_status 2>/dev/null || return
|
||||||
elif [[ -e /run/nordvpnd.sock ]]; then
|
|
||||||
sock=/run/nordvpnd.sock
|
|
||||||
else
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
_p9k_fetch_nordvpn_status $sock 2>/dev/null
|
|
||||||
if [[ $P9K_NORDVPN_SERVER == (#b)([[:alpha:]]##)[[:digit:]]##.nordvpn.com ]]; then
|
if [[ $P9K_NORDVPN_SERVER == (#b)([[:alpha:]]##)[[:digit:]]##.nordvpn.com ]]; then
|
||||||
typeset -g P9K_NORDVPN_COUNTRY_CODE=${${(U)match[1]}//İ/I}
|
typeset -g P9K_NORDVPN_COUNTRY_CODE=${${(U)match[1]}//İ/I}
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue