diff --git a/INSTALL.md b/INSTALL.md index 6579094..0aadac0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -318,4 +318,25 @@ Set the label when there is one client, or more than one client ```bash set -g @dracula-clients-singular client set -g @dracula-clients-plural clients -``` \ No newline at end of file +``` + +#### continuum options + +Hide output if no save has been performed recently +(otherwise, show the continuum save interval) + +```bash +set -g @dracula-continuum-mode alert +``` + +Show the time since the last continuum save + +```bash +set -g @dracula-continuum-mode time +``` + +In alert mode, show if a the last save was performed less then one minute ago (default is 15 seconds) + +```bash +set -g @dracula-continuum-time-threshold 60 +``` diff --git a/scripts/continuum.sh b/scripts/continuum.sh new file mode 100755 index 0000000..c45c514 --- /dev/null +++ b/scripts/continuum.sh @@ -0,0 +1,75 @@ +#!/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 + +# configuration +# @dracula-continuum-mode default (default|alert|time) +# @dracula-continuum-time-threshold 15 + +alert_mode="@dracula-continuum-mode" +time_threshold="@dracula-continuum-time-threshold" +warn_threshold=15 + +last_auto_save_option="@continuum-save-last-timestamp" +auto_save_interval_option="@continuum-save-interval" +auto_save_interval_default="15" + +current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source $current_dir/utils.sh + +current_timestamp() { + echo "$(date +%s)" +} + +time_since_last_run_passed() { + local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "0")" + printf "%s" "$(($(current_timestamp) - last_saved_timestamp))" +} + +print_status() { + local mode="$(get_tmux_option "$alert_mode" "default")" + local threshold="$(get_tmux_option "$time_threshold" "15")" + local save_int="$(get_tmux_option "$auto_save_interval_option" "$auto_save_interval_default")" + local interval_seconds="$((save_int * 60))" + local status="" + local time_delta="$(time_since_last_run_passed)" + local time_delta_minutes="$((time_delta / 60))" + + case "$mode" in + time) + if [[ $save_int -gt 0 ]]; then + if [[ "$time_delta" -gt $((interval_seconds+warn_threshold)) ]]; then + status="no save after $time_delta_minutes minutes!" + else + status="$time_delta_minutes" + fi + else + status="off" + fi + ;; + + alert) + if [[ "$time_delta" -gt $((interval_seconds+warn_threshold)) ]]; then + status="no save after $time_delta_minutes minutes!" + elif [[ "$time_delta" -le "$threshold" ]]; then + status="saved" + elif [[ $save_int -gt 0 ]]; then + status="" + else + status="off" + fi + ;; + + *) + if [[ "$time_delta" -le "$threshold" ]]; then + status="saved" + elif [[ $save_int -gt 0 ]]; then + status="$save_int" + else + status="off" + fi + ;; + esac + echo "$status" +} +print_status diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2354e76..0bf19c3 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -212,6 +212,10 @@ main() IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-terraform-colors" "light_purple dark_gray") script="#($current_dir/terraform.sh $terraform_label)" + elif [ $plugin = "continuum" ]; then + IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-continuum-colors" "cyan dark_gray") + script="#($current_dir/continuum.sh)" + elif [ $plugin = "weather" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") script="#($current_dir/weather_wrapper.sh $show_fahrenheit $show_location $fixed_location)"