From 643d51c00cd0d45704aa8245a08b54caf21d3a95 Mon Sep 17 00:00:00 2001 From: Mykhailo Nikiforov Date: Thu, 20 Apr 2023 14:59:54 +0300 Subject: [PATCH 1/2] fix weather script --- scripts/dracula.sh | 15 +----------- scripts/sleep_weather.sh | 48 -------------------------------------- scripts/weather_wrapper.sh | 31 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 62 deletions(-) delete mode 100755 scripts/sleep_weather.sh create mode 100755 scripts/weather_wrapper.sh diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 43f8b8f..deb7721 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -7,8 +7,6 @@ source $current_dir/utils.sh main() { - datafile=/tmp/.dracula-tmux-data - # set configuration option variables show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) show_location=$(get_tmux_option "@dracula-show-location" true) @@ -67,11 +65,6 @@ main() left_sep="$show_left_sep" fi - # start weather script in background - if [[ "${plugins[@]}" =~ "weather" ]]; then - $current_dir/sleep_weather.sh $show_fahrenheit $show_location $fixed_location & - fi - # Set timezone unless hidden by configuration case $show_timezone in false) @@ -186,14 +179,8 @@ main() script="#($current_dir/kubernetes_context.sh $show_kubernetes_context_label)" elif [ $plugin = "weather" ]; then - # wait unit $datafile exists just to avoid errors - # this should almost never need to wait unless something unexpected occurs - while [ ! -f $datafile ]; do - sleep 0.01 - done - IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") - script="#(cat $datafile)" + script="#($current_dir/weather_wrapper.sh $show_fahrenheit $show_location $fixed_location)" elif [ $plugin = "time" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white") diff --git a/scripts/sleep_weather.sh b/scripts/sleep_weather.sh deleted file mode 100755 index 869b3d8..0000000 --- a/scripts/sleep_weather.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -# setting the locale, some users have issues with different locales, this forces the correct one -export LC_ALL=en_US.UTF-8 - -#wrapper script for running weather on interval - -fahrenheit=$1 -location=$2 -fixedlocation=$3 - -LOCKFILE=/tmp/.dracula-tmux-weather.lock -DATAFILE=/tmp/.dracula-tmux-data - -ensure_single_process() -{ - # check for another running instance of this script and terminate it if found - [ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)" - echo $$ > $LOCKFILE -} - -main() -{ - ensure_single_process - - current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - - if [ ! -f $DATAFILE ]; then - printf "Loading..." > $DATAFILE - fi - - $current_dir/weather.sh > $DATAFILE - - while tmux has-session &> /dev/null - do - $current_dir/weather.sh $fahrenheit $location $fixedlocation > $DATAFILE - if tmux has-session &> /dev/null - then - sleep 1200 - else - break - fi - done - - rm $LOCKFILE -} - -#run main driver function -main diff --git a/scripts/weather_wrapper.sh b/scripts/weather_wrapper.sh new file mode 100755 index 0000000..75dc1f3 --- /dev/null +++ b/scripts/weather_wrapper.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# setting the locale, some users have issues with different locales, this forces the correct one +export LC_ALL=en_US.UTF-8 + +#wrapper script for running weather on interval + +fahrenheit=$1 +location=$2 +fixedlocation=$3 + +DATAFILE=/tmp/.dracula-tmux-data +LAST_EXEC_FILE="/tmp/.dracula-tmux-weather-last-exec" +RUN_EACH=1200 +TIME_NOW=$(date +%s) +TIME_LAST=$(cat "${LAST_EXEC_FILE}" 2>/dev/null || echo "0") + +main() +{ + current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + + if [ "$(expr ${TIME_LAST} + ${RUN_EACH})" -lt "${TIME_NOW}" ]; then + # Run weather script here + $current_dir/weather.sh $fahrenheit $location $fixedlocation > "${DATAFILE}" + echo "${TIME_NOW}" > "${LAST_EXEC_FILE}" + fi + + cat "${DATAFILE}" +} + +#run main driver function +main From 92a9a471c432ce1f495cbacbc459c8ae6ca85d28 Mon Sep 17 00:00:00 2001 From: Mykhailo Nikiforov Date: Sat, 22 Apr 2023 12:55:21 +0300 Subject: [PATCH 2/2] fix: default value for the time format should be empty --- scripts/dracula.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 43f8b8f..d344c42 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -24,7 +24,7 @@ main() show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) - time_format=$(get_tmux_option "@dracula-time-format" "%Y-%m-%d(%a) %H:%M") + time_format=$(get_tmux_option "@dracula-time-format" "") show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true)