Cache: Move cache file source to info function

This commit is contained in:
Dylan Araps 2016-12-02 20:34:31 +11:00
parent b36528dd80
commit 72c7046a95

View file

@ -919,12 +919,6 @@ get_cpu_usage() {
} }
get_gpu() { get_gpu() {
# Use cache if it exists
if [[ -f "${cache_dir}/neofetch/gpu" ]]; then
source "${cache_dir}/neofetch/gpu"
return
fi
case "$os" in case "$os" in
"Linux" | "GNU") "Linux" | "GNU")
gpu="$(PATH="/sbin:$PATH" lspci -mm | awk -F '\\"|\\" \\"' '/Display|3D|VGA/ {print $3 " " $4}')" gpu="$(PATH="/sbin:$PATH" lspci -mm | awk -F '\\"|\\" \\"' '/Display|3D|VGA/ {print $3 " " $4}')"
@ -1733,23 +1727,17 @@ get_local_ip() {
} }
get_public_ip() { get_public_ip() {
# Use cache if available if type -p dig >/dev/null; then
if [[ -f "${cache_dir}/neofetch/public_ip" ]]; then public_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com)"
source "${cache_dir}/neofetch/public_ip" [[ "$public_ip" =~ ^\; ]] && unset public_ip
fi
else if [[ -z "$public_ip" ]] && type -p curl >/dev/null; then
if type -p dig >/dev/null; then public_ip="$(curl --max-time 10 -w '\n' "$public_ip_host")"
public_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com)" fi
[[ "$public_ip" =~ ^\; ]] && unset public_ip
fi
if [[ -z "$public_ip" ]] && type -p curl >/dev/null; then if [[ -z "$public_ip" ]] && type -p wget >/dev/null; then
public_ip="$(curl --max-time 10 -w '\n' "$public_ip_host")" public_ip="$(wget -T 10 -qO- "$public_ip_host")"
fi
if [[ -z "$public_ip" ]] && type -p wget >/dev/null; then
public_ip="$(wget -T 10 -qO- "$public_ip_host")"
fi
fi fi
cache "public_ip" "$public_ip" cache "public_ip" "$public_ip"
@ -2355,8 +2343,15 @@ info() {
# $1 is the subtitle # $1 is the subtitle
subtitle="$1" subtitle="$1"
# Call the function and update variable # Use cache if it exists
"get_${2:-$1}" 2>/dev/null if [[ -f "${cache_dir}/neofetch/${2}" ]]; then
source "${cache_dir}/neofetch/${2}"
else
# Call the function.
"get_${2:-$1}" 2>/dev/null
fi
# Update the variable
output="${2:-$1}" output="${2:-$1}"
# Trim whitespace # Trim whitespace