-
Notifications
You must be signed in to change notification settings - Fork 340
Synchronize Panes: new feature auto-hide
#360
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
base: master
Are you sure you want to change the base?
Synchronize Panes: new feature auto-hide
#360
Conversation
feat/fix/multi battery display
…chronize-panes-auto-hide` This allows the user to hide the Sync label (`@dracula-synchronize-panes-label`) from the status bar when sync is in the `off` state
…panes-refresh-rate`) that takes precedence over `@dracula-refresh-rate` This enables the user to set a custom `synchronize-panes` refresh rate, which may need to be more frequent than other plugins
📝 WalkthroughWalkthroughAdds two tmux options to documentation and updates synchronize_panes.sh to support a refresh-rate override and an auto-hide output mode, alters output formatting based on status and auto-hide, and adjusts variable initialization order while preserving the sleep-based refresh. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant TMUX as tmux env/options
participant Script as synchronize_panes.sh
participant Output as Status Line
Note over Script: Start tick
Script->>TMUX: read synchronize_panes status (on/off)
Script->>TMUX: read @dracula-synchronize-panes-refresh-rate
alt RATE override set
Script->>Script: RATE = override
else no override
Script->>Script: RATE = default
end
Script->>TMUX: read @dracula-synchronize-panes-auto-hide (default false)
Script->>Script: set label (synchronize_panes_label)
alt auto_hide == true and status == "on"
Script->>Output: echo label
Note right of Output: New conditional output (auto-hide)
else otherwise
Script->>Output: echo "label status"
end
Script->>Script: sleep RATE
Note over Script: End tick
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
scripts/synchronize_panes.sh (4)
19-25
: Per-widget refresh override: good addition; add basic validation.Current logic accepts any string; a non-numeric value will make
sleep
fail. Recommend validating and falling back to the global rate.- RATE_OVERRIDE=$(get_tmux_option "@dracula-synchronize-panes-refresh-rate" "") - if [[ -n "$RATE_OVERRIDE" ]]; then - RATE="$RATE_OVERRIDE" - fi + RATE_OVERRIDE=$(get_tmux_option "@dracula-synchronize-panes-refresh-rate" "") + if [[ -n "$RATE_OVERRIDE" ]]; then + # accept integers or decimals like 0.5; clamp to a sane minimum to avoid busy looping + if [[ "$RATE_OVERRIDE" =~ ^([0-9]+)(\.[0-9]+)?$ ]]; then + RATE="$RATE_OVERRIDE" + # optional clamp + (( $(awk "BEGIN{print ($RATE<0.1)}") )) && RATE=0.1 + fi + fi
26-26
: Boolean option parsing is case-sensitive.You compare strictly to 'true'. Consider normalizing to lowercase to avoid surprises from users setting True/TRUE.
- synchronize_panes_auto_hide=$(get_tmux_option "@dracula-synchronize-panes-auto-hide" "false") + synchronize_panes_auto_hide=$(get_tmux_option "@dracula-synchronize-panes-auto-hide" "false") + synchronize_panes_auto_hide="${synchronize_panes_auto_hide,,}"
28-36
: Confirm intended UX: label-only when on, nothing when off.With auto-hide=true: you output only the label when sync is on, and nothing when it’s off. That matches “hide when off” but also removes the “on” suffix entirely. Confirm this is desired for consistency with other widgets.
You can reduce nesting and make behavior explicit:
- if [[ "$synchronize_panes_auto_hide" == 'true' ]]; then - if [[ "$synchronize_panes_status" == 'on' ]]; then - echo "$synchronize_panes_label" - fi - else - echo "$synchronize_panes_label $synchronize_panes_status" - fi + if [[ "$synchronize_panes_auto_hide" == 'true' && "$synchronize_panes_status" == 'off' ]]; then + : # hide + elif [[ "$synchronize_panes_auto_hide" == 'true' ]]; then + echo "$synchronize_panes_label" + else + echo "$synchronize_panes_label $synchronize_panes_status" + fi
38-38
: Portability of fractional sleep.Docs suggest “0.5”; fractional
sleep
is GNU/coreutils-friendly but may vary with BusyBox/older BSDs. Either document the requirement or guard with integer fallback.Add a pre-check:
- sleep $RATE + if ! sleep "$RATE" 2>/dev/null; then + # fallback to nearest integer second + sleep "${RATE%.*}" + fidocs/CONFIG.md (1)
815-821
: Clarify behavior and constraints for new options.
- Spell out the exact behavior with auto-hide: when true, the widget shows only the label while sync is on, and hides entirely when off.
- Note that @dracula-synchronize-panes-refresh-rate overrides this widget only; it does not change @dracula-refresh-rate.
- Mention that boolean values are case-sensitive ('true'/'false').
- If you intend to support decimals (e.g., "0.5"), add a brief portability note that fractional sleep requires GNU/coreutils or compatible environments.
Proposed wording:
# synchronize-panes ... Optional: set -g @dracula-synchronize-panes-auto-hide true # when true: shows only the label while sync is on; hides the widget when sync is off set -g @dracula-synchronize-panes-refresh-rate "0.5" # refresh rate for this widget only; does not affect @dracula-refresh-rate # Note: values are case-sensitive; use 'true'/'false'. Fractional rates require a shell/coreutils that support fractional `sleep`.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/CONFIG.md
(1 hunks)scripts/synchronize_panes.sh
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
scripts/synchronize_panes.sh (1)
scripts/utils.sh (1)
get_tmux_option
(3-12)
🔇 Additional comments (1)
scripts/synchronize_panes.sh (1)
10-13
: No action needed:get_tmux_window_option
is defined in scripts/utils.sh and correctly sourced in scripts/synchronize_panes.sh.
…es in `CONFIG.md`
19e3e74
to
215af3e
Compare
Ello,
This PR does the following
@dracula-synchronize-panes-auto-hide
.@dracula-synchronize-panes-refresh-rate
@dracula-refresh-rate
Here's how to configure it in practice:
I'm already using this and I haven't noticed any issues (yet). Let me know what you think or any changes I need to make to get this merged.
Cheers!