diff --git a/.github/assets/tmux-nova-plugin-variables.png b/.github/assets/tmux-nova-plugin-variables.png new file mode 100644 index 0000000..5140257 Binary files /dev/null and b/.github/assets/tmux-nova-plugin-variables.png differ diff --git a/.github/documentation.md b/.github/documentation.md index 93051fa..e45f256 100644 --- a/.github/documentation.md +++ b/.github/documentation.md @@ -1,4 +1,4 @@ -## Documentation +## Documentation ### Pane @@ -120,3 +120,38 @@ set -g @nova-segment-bright-colors "#282a36 #f8f8f2" set -g @nova-segments-1-left "bleft" set -g @nova-segments-1-right "bright" ``` + +### Use plugin variables + +Define variables you want to load to be used in segments. + +
+ +```bash +# Load plugin variables to be used in tmux-nova, separated by space +# before declaration of plugins +run-shell "~/.tmux/plugins/tmux-nova/scripts/load_plugin_variables.sh pomodoro_status music_percentage music_status artist track" + +# List of plugins +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-battery' +set -g @plugin 'robhurring/tmux-spotify' +set -g @plugin 'olimorris/tmux-pomodoro-plus' +set -g @plugin 'o0th/tmux-nova' # Must be the last on the list + +set -g @nova-segment-pomodoro "#(#{pomodoro_status})" +set -g @nova-segment-pomodoro-colors "colour1 colour8" + +set -g @nova-segment-battery "#(#{battery_percentage})" +set -g @nova-segment-battery-colors "colour11 colour8" + +set -g @nova-segment-spotify "#(#{music_status}) #(#{artist}): #(#{track})" +set -g @nova-segment-spotify-colors "colour4 colour8" + +set -g @nova-segment-time "%d/%m %H:%M" +set -g @nova-segment-time-colors "colour5 colour8" + +set -g @nova-segments-0-right "pomodoro spotify battery time" +``` diff --git a/scripts/load_plugin_variables.sh b/scripts/load_plugin_variables.sh new file mode 100755 index 0000000..edb55ca --- /dev/null +++ b/scripts/load_plugin_variables.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +export LC_ALL=en_US.UTF-8 + +tmux set-option -g status-left "" + +tmux set-environment -g @nova-load-variables "" +all="" + +for var in "$@" +do + tmux set-option -ga status-left "#{$var}*" + all+="$var " +done +tmux set-environment -g @nova-load-variables "$all" diff --git a/scripts/nova.sh b/scripts/nova.sh index e9f93de..7303a3e 100644 --- a/scripts/nova.sh +++ b/scripts/nova.sh @@ -74,6 +74,26 @@ pane_active_border_style=$(get_option "@nova-pane-active-border-style" "#44475a" tmux set-option -g pane-border-style "fg=${pane_border_style}" tmux set-option -g pane-active-border-style "fg=${pane_active_border_style}" +# +# load variables +# + +var_names=$(tmux show-environment -g @nova-load-variables | sed 's/@nova-load-variables=//') +IFS=' ' read -r -a var_names<<< $var_names +length=${#var_names[@]} + +vars=$(get_option "status-left" "") +IFS='*' read -r -a vars<<< $vars + +for ((j = 0; j < ${length}; j++)); do + interpolated_var="${vars[$j]}" + var_name="${var_names[$j]}" + + stripped_var=$(echo $interpolated_var | sed 's/#(//' | sed 's/)//') + tmux set-environment -g "$var_name" "$stripped_var" +done + + # # segments-0-left #