From 1b47cab32a1ed913fe87e5eda6df85b5625706f5 Mon Sep 17 00:00:00 2001 From: "Jetzer, Bill" Date: Thu, 21 Nov 2019 12:50:31 -0600 Subject: [PATCH] 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. --- .tmux.conf | 18 ++++++++++++++++++ .tmux.conf.local | 4 ++++ README.md | 2 ++ 3 files changed, 24 insertions(+) diff --git a/.tmux.conf b/.tmux.conf index 6d46f09..d75e535 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -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') # diff --git a/.tmux.conf.local b/.tmux.conf.local index 53b94c7..57230c2 100644 --- a/.tmux.conf.local +++ b/.tmux.conf.local @@ -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 ""' +tmux_custom_interval=15 # number of minutes between updates # -- clipboard ----------------------------------------------------------------- diff --git a/README.md b/README.md index e763c3d..d0d5d16 100644 --- a/README.md +++ b/README.md @@ -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