Skip to content

Commit d0cebe0

Browse files
author
Bruno Sutic
committed
Continuum status
1 parent 460350f commit d0cebe0

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
checking if other tmux server is running). Previously, this caused
1010
interpolation command not to be inserted into `status-right` because `tmux
1111
source-file` was falsely detected as another tmux server.
12+
- add `#{continuum_status}` status line interpolation
1213

1314
### v3.0.0, 2015-02-20
1415
- rename the plugin from `tmux-resurrect-auto` to `tmux-continuum`

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ required.
7878
this doc is safe to skip, but you might want to read it if you're using tmux
7979
with `-L` or `-S` flags
8080
- [automatically start tmux after the computer is turned on](docs/automatic_start.md)
81+
- [continuum status in tmux status line](docs/continuum_status.md)
8182

8283
### Other goodies
8384

continuum.tmux

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ start_auto_restore_in_background() {
5656
"$CURRENT_DIR/scripts/continuum_restore.sh" &
5757
}
5858

59+
update_tmux_option() {
60+
local option="$1"
61+
local option_value="$(get_tmux_option "$option")"
62+
# replace interpolation string with a script to execute
63+
local new_option_value="${option_value/$status_interpolation_string/$status_script}"
64+
set_tmux_option "$option" "$new_option_value"
65+
}
66+
5967
main() {
6068
if supported_tmux_version_ok; then
6169
handle_tmux_automatic_start
@@ -72,6 +80,11 @@ main() {
7280
if just_started_tmux_server; then
7381
start_auto_restore_in_background
7482
fi
83+
84+
# Put "#{continuum_status}" interpolation in status-right or
85+
# status-left tmux option to get current tmux continuum status.
86+
update_tmux_option "status-right"
87+
update_tmux_option "status-left"
7588
fi
7689
}
7790
main

docs/continuum_status.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Continuum status in tmux status line
2+
3+
There is an option to display current status of tmux continuum in tmux status
4+
line. This is done via `#{continuum_status}` interpolation and it works with
5+
both `status-right` and `status-left` tmux native options.
6+
7+
Example usage:
8+
9+
set -g status-right 'Continuum status: #{continuum_status}'
10+
11+
When running, `#{continuum_status}` will show continuum save interval:
12+
13+
Continuum status: 15
14+
15+
or if continuous saving is disabled:
16+
17+
Continuum status: off

scripts/continuum_status.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
source "$CURRENT_DIR/helpers.sh"
6+
source "$CURRENT_DIR/variables.sh"
7+
8+
print_status() {
9+
local save_int="$(get_tmux_option "$auto_save_interval_option")"
10+
local status=""
11+
local style_wrap
12+
if [ $save_int -gt 0 ]; then
13+
style_wrap="$(get_tmux_option "$status_on_style_wrap_option" "")"
14+
status="$save_int"
15+
else
16+
style_wrap="$(get_tmux_option "$status_off_style_wrap_option" "")"
17+
status="off"
18+
fi
19+
20+
if [ -n "$style_wrap" ]; then
21+
status="${style_wrap/$status_wrap_string/$status}"
22+
fi
23+
echo "$status"
24+
}
25+
print_status

scripts/variables.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ auto_start_config_default=""
2525

2626
osx_auto_start_file_name="Tmux.Start.plist"
2727
osx_auto_start_file_path="${HOME}/Library/LaunchAgents/${osx_auto_start_file_name}"
28+
29+
status_interpolation_string="\#{continuum_status}"
30+
status_script="#($CURRENT_DIR/scripts/continuum_status.sh)"
31+
# below options set style/color for #{continuum_status} interpolation
32+
status_on_style_wrap_option="@continuum-status-on-wrap-style" # example value: "#[fg=green]#{value}#[fg=white]"
33+
status_off_style_wrap_option="@continuum-status-off-wrap-style" # example value: "#[fg=yellow,bold]#{value}#[fg=white,nobold]"
34+
status_wrap_string="\#{value}"

0 commit comments

Comments
 (0)