Public IP: Add caching
This commit is contained in:
parent
112613410d
commit
00447db6d7
1 changed files with 22 additions and 10 deletions
12
neofetch
12
neofetch
|
@ -1743,6 +1743,12 @@ get_local_ip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
get_public_ip() {
|
get_public_ip() {
|
||||||
|
# Use cache if available
|
||||||
|
if [[ -f "/tmp/neofetch/public_ip" ]]; then
|
||||||
|
source "/tmp/neofetch/public_ip"
|
||||||
|
elif [[ -f "/Library/Caches/neofetch/public_ip" ]]; then
|
||||||
|
source "/Library/Caches/neofetch/public_ip"
|
||||||
|
else
|
||||||
if type -p dig >/dev/null; then
|
if type -p dig >/dev/null; then
|
||||||
public_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com)"
|
public_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com)"
|
||||||
[[ "$public_ip" =~ ^\; ]] && unset public_ip
|
[[ "$public_ip" =~ ^\; ]] && unset public_ip
|
||||||
|
@ -1755,6 +1761,12 @@ get_public_ip() {
|
||||||
if [[ -z "$public_ip" ]] && type -p wget >/dev/null; then
|
if [[ -z "$public_ip" ]] && type -p wget >/dev/null; then
|
||||||
public_ip="$(wget -T 10 -qO- "$public_ip_host")"
|
public_ip="$(wget -T 10 -qO- "$public_ip_host")"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$os" in
|
||||||
|
"Mac OS X"*) cache "public_ip" "$public_ip" "/Library/Caches" ;;
|
||||||
|
*) cache "public_ip" "$public_ip" "/tmp" ;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
get_users() {
|
get_users() {
|
||||||
|
|
Loading…
Reference in a new issue