From fab703fbb6d895c62cd14b7ab4478a85f0bd5961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EB=B3=91=EC=A4=80?= Date: Fri, 25 Apr 2025 17:39:39 +0900 Subject: [PATCH 1/2] improve: cache public ip address --- scripts/network-public-ip.sh | 24 ++++++++++++++++++------ scripts/weather_wrapper.sh | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/network-public-ip.sh b/scripts/network-public-ip.sh index ff962347..4cd07526 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 From 1be2fa7175c02e4c00710f777377d11a422a6c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EB=B3=91=EC=A4=80?= Date: Fri, 2 May 2025 15:55:14 +0900 Subject: [PATCH 2/2] update: remove padding after icon --- scripts/network-public-ip.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/network-public-ip.sh b/scripts/network-public-ip.sh index 4cd07526..7a1ccacd 100755 --- a/scripts/network-public-ip.sh +++ b/scripts/network-public-ip.sh @@ -19,7 +19,7 @@ main() { IP_SERVER="ifconfig.me" ip=$(curl -s "$IP_SERVER") - echo "$(get_tmux_option "@dracula-network-public-ip-label" "") $ip" > "${DATAFILE}" + echo "$(get_tmux_option "@dracula-network-public-ip-label" "")$ip" > "${DATAFILE}" printf '%s' "$_now" > "${LAST_EXEC_FILE}" fi