Skip to content

Cache ip address in network-public-ip plugin #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions scripts/network-public-ip.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion scripts/weather_wrapper.sh
Original file line number Diff line number Diff line change
@@ -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