Skip to content
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

Customise status with time remaining #120

Open
jmetz opened this issue Feb 3, 2023 · 4 comments
Open

Customise status with time remaining #120

jmetz opened this issue Feb 3, 2023 · 4 comments

Comments

@jmetz
Copy link

jmetz commented Feb 3, 2023

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
Copy link

j-rahman commented May 4, 2023

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

@jmetz
Copy link
Author

jmetz commented May 5, 2023

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
Copy link
Author

jmetz commented May 5, 2023

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
Copy link

Thank you for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants