mirror of
1
0
Fork 0

Add `#{custom}` builtin, run on a schedule

Add a new builtin variable `#{custom}` which executes a command stored
in ~/.tmux.conf.local's `tmux_custom_command` variable.  But only
execute it every `tmux_custom_interval` minutes.

Useful for showing information that changes slowly over time.  For
instance, you can update the weather every 15 minutes instead of every
`status-interval` (typically 10) seconds.
This commit is contained in:
Jetzer, Bill 2019-11-21 12:50:31 -06:00
parent 01c91ba523
commit 1b47cab32a
3 changed files with 24 additions and 0 deletions

View File

@ -645,6 +645,14 @@ run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3
# esac
# }
#
# # update custom message on its own schedule
# _custom() {
# if [ $(date +%s) -ge $(($tmux_custom_updated + 60 * ${tmux_custom_interval:-0})) ]; then
# tmux set -g @custom "$(eval $tmux_custom_command)"
# tmux setenv -g tmux_custom_updated $(date +%s)
# fi
# }
#
# _split_window() {
# tty=${1:-$(tmux display -p '#{pane_tty}')}
# shift
@ -1178,6 +1186,16 @@ run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3
# ;;
# esac
#
# case "$status_left $status_right" in
# *'#{custom}'*)
# status_left=$(echo "$status_left" | sed -E \
# -e 's/#\{(\?)?custom/#\{\1@custom/g')
# status_right=$(echo "$status_right" | sed -E \
# -e 's/#\{(\?)?custom/#\{\1@custom/g')
# status_right="#(cut -c3- ~/.tmux.conf | sh -s _custom)$status_right"
# ;;
# esac
#
# status_left=$(echo "$status_left" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g')
# status_right=$(echo "$status_right" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g')
#

View File

@ -260,6 +260,10 @@ tmux_conf_battery_status_discharging='↓' # U+2193
tmux_conf_theme_clock_colour='#00afff' # light blue
tmux_conf_theme_clock_style='24'
# Custom message configuration. Enter a command and interval here, and include
# "#{custom}" in tmux_conf_theme_status_left or tmux_conf_theme_status_right
tmux_custom_command='curl wttr.in/?format=3 2>/dev/null || echo "<weather unavailable>"'
tmux_custom_interval=15 # number of minutes between updates
# -- clipboard -----------------------------------------------------------------

View File

@ -245,6 +245,8 @@ This configuration supports the following builtin variables:
- `#{battery_status}`: is battery charging or discharging?
- `#{battery_vbar}`: vertical battery charge bar
- `#{circled_session_name}`: circled session number, up to 20
- `#{custom}`: custom command, specified in `tmux_custom_command`, and
executed once every `tmux_custom_interval` minutes
- `#{hostname}`: SSH/Mosh aware hostname information
- `#{hostname_ssh}`: SSH/Mosh aware hostname information, blank when not
connected to a remote server through SSH/Mosh