diff --git a/scripts/network-public-ip.sh b/scripts/network-public-ip.sh index ff962347..7a1ccacd 100755 --- a/scripts/network-public-ip.sh +++ b/scripts/network-public-ip.sh @@ -3,15 +3,27 @@ # setting the locale, some users have issues with different locales, this forces the correct one export LC_ALL=en_US.UTF-8 -current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $current_dir/utils.sh +DATAFILE="/tmp/.dracula-tmux-public-ip-data" +LAST_EXEC_FILE="/tmp/.dracula-tmux-public-ip-last-exec" +INTERVAL=1200 main() { - IP_SERVER="ifconfig.me" - ip=$(curl -s "$IP_SERVER") + local _current_dir _last _now + current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + _last=$(cat "$LAST_EXEC_FILE" 2>/dev/null || echo 0) + _now=$(date +%s) - IP_LABEL=$(get_tmux_option "@dracula-network-public-ip-label" "") - echo "$IP_LABEL $ip" + source $current_dir/utils.sh + + if (((_now - _last) > INTERVAL)); then + IP_SERVER="ifconfig.me" + ip=$(curl -s "$IP_SERVER") + + echo "$(get_tmux_option "@dracula-network-public-ip-label" "")$ip" > "${DATAFILE}" + printf '%s' "$_now" > "${LAST_EXEC_FILE}" + fi + + cat "${DATAFILE}" } # run the main driver diff --git a/scripts/weather_wrapper.sh b/scripts/weather_wrapper.sh index ba74c22f..b1a820a6 100755 --- a/scripts/weather_wrapper.sh +++ b/scripts/weather_wrapper.sh @@ -2,7 +2,7 @@ # setting the locale, some users have issues with different locales, this forces the correct one export LC_ALL=en_US.UTF-8 -DATAFILE="/tmp/.dracula-tmux-data" +DATAFILE="/tmp/.dracula-tmux-weather-data" LAST_EXEC_FILE="/tmp/.dracula-tmux-weather-last-exec" INTERVAL=1200