From 5af1faa367d56a70a871c85e3a3f377d11622d98 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Fri, 28 Oct 2022 03:11:39 -0400 Subject: [PATCH 1/6] Add plugin for tmux-continuum status --- INSTALL.md | 23 +++++++++++++- scripts/continuum.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++ scripts/dracula.sh | 4 +++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100755 scripts/continuum.sh 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)" From 14300a6e751e3ee169f22847d17fa9610c274f4f Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Fri, 28 Oct 2022 06:34:42 -0400 Subject: [PATCH 2/6] Improve tmux-continuum status plugin --- INSTALL.md | 17 +++--- scripts/continuum.sh | 130 ++++++++++++++++++++++++++++++------------- 2 files changed, 98 insertions(+), 49 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 0aadac0..d91b1d1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -322,20 +322,17 @@ set -g @dracula-clients-plural clients #### continuum options -Hide output if no save has been performed recently -(otherwise, show the continuum save interval) +Set the output mode. Options are: +- **countdown**: Show a T- countdown to the next save (default) +- **time**: Show the time since the last save +- **alert**: Hide output if no save has been performed recently +- **interval**: Show the continuum save interval ```bash -set -g @dracula-continuum-mode alert +set -g @dracula-continuum-mode countdown ``` -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) +Show if the last save was performed less than 60 seconds ago (default threshold is 15 seconds) ```bash set -g @dracula-continuum-time-threshold 60 diff --git a/scripts/continuum.sh b/scripts/continuum.sh index c45c514..1e4229f 100755 --- a/scripts/continuum.sh +++ b/scripts/continuum.sh @@ -1,15 +1,28 @@ #!/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 +if command -v gdate &>/dev/null; then + DATE=gdate +else + DATE=date +fi # configuration -# @dracula-continuum-mode default (default|alert|time) +# @dracula-continuum-mode default (countdown|time|alert|interval) # @dracula-continuum-time-threshold 15 alert_mode="@dracula-continuum-mode" time_threshold="@dracula-continuum-time-threshold" -warn_threshold=15 +warn_threshold=360 +first_save="@dracula-continuum-first-save" +# tmux-resurrect and tmux-continuum options +if [ -d "$HOME/.tmux/resurrect" ]; then + default_resurrect_dir="$HOME/.tmux/resurrect" +else + default_resurrect_dir="${XDG_DATA_HOME:-$HOME/.local/share}"/tmux/resurrect +fi +resurrect_dir_option="@resurrect-dir" last_auto_save_option="@continuum-save-last-timestamp" auto_save_interval_option="@continuum-save-interval" auto_save_interval_default="15" @@ -21,55 +34,94 @@ 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))" +set_tmux_option() { + local option="$1" + local value="$2" + tmux set-option -gq "$option" "$value" +} + +# tmux-resurrect dir +resurrect_dir() { + if [ -z "$_RESURRECT_DIR" ]; then + local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")" + # expands tilde, $HOME and $HOSTNAME if used in @resurrect-dir + echo "$path" | sed "s,\$HOME,$HOME,g; s,\$HOSTNAME,$(hostname),g; s,\~,$HOME,g" + else + echo "$_RESURRECT_DIR" + fi +} +_RESURRECT_DIR="$(resurrect_dir)" + +last_resurrect_file() { + echo "$(resurrect_dir)/last" +} + +last_saved_timestamp() { + local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "")" + local first_save_timestamp="$(get_tmux_option "$first_save" "")" + # continuum sets the last save timestamp to the current time on first load if auto_save_option is not set + # so we can outrace it and detect that last_uato_save_option is empty and the timestamp is a dummy save + if [ -z "$first_save_timestamp" ]; then + last_saved_timestamp="$($DATE -r "$(last_resurrect_file)" +%s)" || last_saved_timestamp=0 + set_tmux_option "$first_save" "$last_saved_timestamp" + elif [ "$first_save_timestamp" != "done" ]; then + last_saved_timestamp="$($DATE -r "$(last_resurrect_file)" +%s)" || last_saved_timestamp=0 + if [ "$last_saved_timestamp" -gt "$first_save_timestamp" ]; then + set_tmux_option "$first_save" "done" + else + last_saved_timestamp="$first_save_timestamp" + fi + fi + echo "$last_saved_timestamp" } print_status() { - local mode="$(get_tmux_option "$alert_mode" "default")" - local threshold="$(get_tmux_option "$time_threshold" "15")" + local mode="$(get_tmux_option "$alert_mode" "countdown")" + local info_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 last_timestamp="$(last_saved_timestamp)" + local time_delta="$(($(current_timestamp) - last_timestamp))" 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 - ;; + if [[ $save_int -gt 0 ]]; then + if [[ "$time_delta" -gt $((interval_seconds + warn_threshold)) ]]; then + if [[ "$mode" == "countdown" ]]; then + # continuum timestamp may be different than file timestamp on first load + local last_continuum_timestamp="$(get_tmux_option "$last_auto_save_option" "")" + time_delta="$(($(current_timestamp) - last_continuum_timestamp))" + time_delta_minutes="$((time_delta / 60))" - 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="" + status="last save: $($DATE -d "@$last_timestamp" '+%F %T'); next: T$(printf '%+d' "$((time_delta_minutes - save_int)) min")" else - status="off" + status="last save: $($DATE -d "@$last_timestamp" '+%F %T')" fi - ;; + elif [[ "$time_delta" -le "$info_threshold" ]]; then + status="saved" + else + case "$mode" in + countdown) + status="T$(printf '%+d' "$((time_delta_minutes - save_int))")min"; + ;; + + time) + status="$time_delta_minutes"; + ;; + + alert) + status="" + ;; + + interval) + status="$save_int" + ;; + esac + fi + 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 From 67cde9d1ae2ac980a7d1f35c03fd09702db3c233 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Fri, 28 Oct 2022 12:14:50 -0400 Subject: [PATCH 3/6] Improve date compat in tmux-continuum status --- scripts/continuum.sh | 49 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/scripts/continuum.sh b/scripts/continuum.sh index 1e4229f..54ba773 100755 --- a/scripts/continuum.sh +++ b/scripts/continuum.sh @@ -1,11 +1,6 @@ #!/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 -if command -v gdate &>/dev/null; then - DATE=gdate -else - DATE=date -fi # configuration # @dracula-continuum-mode default (countdown|time|alert|interval) @@ -34,6 +29,42 @@ current_timestamp() { echo "$(date +%s)" } +file_mtime() { + if [ ! -f "$1" ]; then + echo 0 + return + fi + case $(uname -s) in + Linux|Darwin) + date -r "$1" +%s + ;; + + FreeBSD) + stat -f %m "$1" + ;; + + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # TODO - windows compatability + ;; + esac +} + +timestamp_date() { + case $(uname -s) in + Linux) + date -d "@$1" "$2" + ;; + + Darwin|FreeBSD) + date -r "$1" "$2" + ;; + + CYGWIN*|MINGW32*|MSYS*|MINGW*) + # TODO - windows compatability + ;; + esac +} + set_tmux_option() { local option="$1" local value="$2" @@ -62,10 +93,10 @@ last_saved_timestamp() { # continuum sets the last save timestamp to the current time on first load if auto_save_option is not set # so we can outrace it and detect that last_uato_save_option is empty and the timestamp is a dummy save if [ -z "$first_save_timestamp" ]; then - last_saved_timestamp="$($DATE -r "$(last_resurrect_file)" +%s)" || last_saved_timestamp=0 + last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=0 set_tmux_option "$first_save" "$last_saved_timestamp" elif [ "$first_save_timestamp" != "done" ]; then - last_saved_timestamp="$($DATE -r "$(last_resurrect_file)" +%s)" || last_saved_timestamp=0 + last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=0 if [ "$last_saved_timestamp" -gt "$first_save_timestamp" ]; then set_tmux_option "$first_save" "done" else @@ -93,9 +124,9 @@ print_status() { time_delta="$(($(current_timestamp) - last_continuum_timestamp))" time_delta_minutes="$((time_delta / 60))" - status="last save: $($DATE -d "@$last_timestamp" '+%F %T'); next: T$(printf '%+d' "$((time_delta_minutes - save_int)) min")" + status="last save: $(timestamp_date "$last_timestamp" '+%F %T'); next: T$(printf '%+d' "$((time_delta_minutes - save_int))")min" else - status="last save: $($DATE -d "@$last_timestamp" '+%F %T')" + status="last save: $(timestamp_date "$last_timestamp" '+%F %T')" fi elif [[ "$time_delta" -le "$info_threshold" ]]; then status="saved" From e0dd39def54e1af2080261f2481e0460ab912998 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Tue, 1 Nov 2022 03:01:33 -0400 Subject: [PATCH 4/6] Improve tmux-continuum status if no save present --- scripts/continuum.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/continuum.sh b/scripts/continuum.sh index 54ba773..a66e897 100755 --- a/scripts/continuum.sh +++ b/scripts/continuum.sh @@ -31,7 +31,7 @@ current_timestamp() { file_mtime() { if [ ! -f "$1" ]; then - echo 0 + echo -1 return fi case $(uname -s) in @@ -93,10 +93,10 @@ last_saved_timestamp() { # continuum sets the last save timestamp to the current time on first load if auto_save_option is not set # so we can outrace it and detect that last_uato_save_option is empty and the timestamp is a dummy save if [ -z "$first_save_timestamp" ]; then - last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=0 + last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=-1 set_tmux_option "$first_save" "$last_saved_timestamp" elif [ "$first_save_timestamp" != "done" ]; then - last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=0 + last_saved_timestamp="$(file_mtime "$(last_resurrect_file)")" || last_saved_timestamp=-1 if [ "$last_saved_timestamp" -gt "$first_save_timestamp" ]; then set_tmux_option "$first_save" "done" else @@ -118,15 +118,18 @@ print_status() { if [[ $save_int -gt 0 ]]; then if [[ "$time_delta" -gt $((interval_seconds + warn_threshold)) ]]; then + if [[ "$last_timestamp" == -1 ]]; then + status="no save" + else + status="last save: $(timestamp_date "$last_timestamp" '+%F %T')" + fi if [[ "$mode" == "countdown" ]]; then # continuum timestamp may be different than file timestamp on first load local last_continuum_timestamp="$(get_tmux_option "$last_auto_save_option" "")" time_delta="$(($(current_timestamp) - last_continuum_timestamp))" time_delta_minutes="$((time_delta / 60))" - status="last save: $(timestamp_date "$last_timestamp" '+%F %T'); next: T$(printf '%+d' "$((time_delta_minutes - save_int))")min" - else - status="last save: $(timestamp_date "$last_timestamp" '+%F %T')" + status="$status; next: T$(printf '%+d' "$((time_delta_minutes - save_int))")min" fi elif [[ "$time_delta" -le "$info_threshold" ]]; then status="saved" From 7a8c436807358d1273016833ef3ed8d5f1fdc963 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Thu, 10 Nov 2022 22:53:25 -0500 Subject: [PATCH 5/6] Trim tmux-continuum status if no save present --- scripts/continuum.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/continuum.sh b/scripts/continuum.sh index a66e897..189e01b 100755 --- a/scripts/continuum.sh +++ b/scripts/continuum.sh @@ -129,7 +129,7 @@ print_status() { time_delta="$(($(current_timestamp) - last_continuum_timestamp))" time_delta_minutes="$((time_delta / 60))" - status="$status; next: T$(printf '%+d' "$((time_delta_minutes - save_int))")min" + status="$status; T$(printf '%+d' "$((time_delta_minutes - save_int))")min" fi elif [[ "$time_delta" -le "$info_threshold" ]]; then status="saved" From cf474c934260ef82e7da7cf71dbf8a1bf6877b70 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 17 Jun 2023 17:28:39 -0400 Subject: [PATCH 6/6] Add tmux-continuum feature to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6ea0860..6fcd9ef 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul - Info if the Panes are synchronized - Spotify playback (needs the tool spotify-tui installed) - Current kubernetes context +- Countdown to tmux-continuum save - Current working directory of tmux pane ## Compatibility