tmux-plugins / tmux-continuum

Continuous saving of tmux environment. Automatic restore when tmux is started. Automatic tmux start when computer is turned on.
MIT License
3.31k stars 149 forks source link

Customise status with time remaining #120

Open jmetz opened 1 year ago

jmetz commented 1 year ago

I wanted to see a "time to next save" instead of just the time between saves, so for now I've just hacked away at https://github.com/tmux-plugins/tmux-continuum/blob/master/scripts/continuum_status.sh, so that I now see:

image

Do you have any plans to add functionality to make such customization easier / not require messing with the internals of this plugin (or is that already possible and I missed it)?

j-rahman commented 1 year ago

Could you please tell me how to incorporate that in my .tmux.conf? Thank you.

jmetz commented 1 year ago

Could you please tell me how to incorporate that in my .tmux.conf? Thank you.

As I mentioned, it's not something you can currently achieve using just the .tmux.conf (which is why this issue exists!).

Here are the changes I made to https://github.com/tmux-plugins/tmux-continuum/blob/master/scripts/continuum_status.sh:

diff --git a/scripts/continuum_status.sh b/scripts/continuum_status.sh
index 280cf00..83b488b 100755
--- a/scripts/continuum_status.sh
+++ b/scripts/continuum_status.sh
@@ -4,21 +4,39 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

 source "$CURRENT_DIR/helpers.sh"
 source "$CURRENT_DIR/variables.sh"
+source "$CURRENT_DIR/shared.sh"
+
+get_interval() {
+   get_tmux_option "$auto_save_interval_option" "$auto_save_interval_default"
+}
+
+
+current_timestamp() {
+   echo "$(date +%s)"
+   "$(date +%s)"
+}

 print_status() {
-   local save_int="$(get_tmux_option "$auto_save_interval_option")"
+        local save_int="$(get_tmux_option "$auto_save_interval_option")"
    local status=""
+   local style_wrap="$(get_tmux_option "$status_on_style_wrap_option" "")"
    local style_wrap
    if [ $save_int -gt 0 ]; then
-       style_wrap="$(get_tmux_option "$status_on_style_wrap_option" "")"
-       status="$save_int"
+            local last_saved_timestamp="$(get_tmux_option "$last_auto_save_option" "0")"
+            local interval_minutes="$(get_interval)"
+            local interval_seconds="$((interval_minutes * 60))"
+            local next_run="$((last_saved_timestamp + $interval_seconds))"
+            local now="$(date +%s)"
+            local secs="$((next_run - now))"
+            local til_next_save=$(printf '%02dh:%02dm:%02ds\n' $((secs/3600)) $((secs%3600/60)) $((secs%60)))
+            status="$til_next_save"
    else
-       style_wrap="$(get_tmux_option "$status_off_style_wrap_option" "")"
-       status="off"
+       style_wrap="$(get_tmux_option "$status_off_style_wrap_option" "")"
+       status="off"

    fi

    if [ -n "$style_wrap" ]; then
-       status="${style_wrap/$status_wrap_string/$status}"
+       status="${style_wrap/$status_wrap_string/$status}"
    fi
    echo "$status"
 }

Git diff attached as a txt file:

tmp.diff.txt

or as a drop-in replacement:

continuum_status.sh.txt

NB: This needs to be renamed to remove the trailing .txt - that was just so that github would accept it!

jmetz commented 1 year ago

The corresponding line in the .tmux.conf that shows the save time and the icon:

set -g status-right '💾#{continuum_status}#[fg=colour233,bg=colour241,bold] %d/%m #[fg=colour233,bg=colour245,bold] %H:%M:%S '
j-rahman commented 1 year ago

Thank you for the explanation.