Skip to content

Added scrolling text to Mac player module and cleaned up functions #356

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

LinkUpGames
Copy link

Initially, I did some work that added a small scrolling text effect to the playerctl plugin last year (#273). I revisited the plugin and decided to do some clean up on it. I decided to expose some more parameters to users such as defining the width of the plugin and also the scrolling speed.

Additionally, I love the new Macos player plugin (#343) and decided to also add a similar scrolling effect for users. I exposed the scrolling speed as a parameter for users that wish to have this option on. I believe that since both of these plugins have very similar functions, there should be a common function that can be used to get the scrolling characters on screen. This function was added to the utils.sh file.

Let me know if you have any questions or if there's something that needs to be fixed up!

Made sure that both modules have scrollable text as an option as exposed
several other parameters that the user can use to customize
Copy link

coderabbitai bot commented Jul 23, 2025

📝 Walkthrough

Walkthrough

Adds horizontal scrolling support and remote-control option wiring: new scroll implementations in scripts/mac-player.sh and scripts/playerctl.sh, a circular slice utility in scripts/utils.sh, tmux configuration options for scrolling and remote buttons, and documentation examples in docs/CONFIG.md.

Changes

Cohort / File(s) Change Summary
Documentation
docs/CONFIG.md
Added examples and new tmux configuration options documenting scrolling and speed settings for mac-player and playerctl.
mac-player script
scripts/mac-player.sh
Added scroll() function; read tmux options @dracula-mac-player-scroll, @dracula-mac-player-scroll-speed, and remote button mappings (remote-play-pause, remote-back, remote-next); conditional caching and output path to drive animated rendering when scrolling is enabled; remote-control binding/unbinding logic; minor change to source quoting.
playerctl script
scripts/playerctl.sh
Removed slice_loop(); added scroll(str, width, speed) and replaced manual slicing loop with calls to scroll; read tmux options @dracula-playerctl-scroll, @dracula-playerctl-width, and @dracula-playerctl-speed.
Utilities
scripts/utils.sh
Added slice_text() for circular substring extraction used by scroll implementations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant tmuxWidget as Widget Script (mac-player/playerctl)
    participant Utils as utils.sh

    User->>tmuxWidget: Widget invoked (periodic/tmux trigger)
    tmuxWidget->>tmuxWidget: Read tmux options (scroll, width/speed, remote mappings)
    alt Scrolling enabled
        tmuxWidget->>Utils: slice_text / scroll iterations
        Utils-->>tmuxWidget: frame substrings
        tmuxWidget->>User: Output animated frames (carriage-return updates)
    else Scrolling disabled
        tmuxWidget->>User: Output cached/truncated text
    end
    opt Remote access enabled
        User->>tmuxWidget: Remote button press
        tmuxWidget->>tmuxWidget: Handle mapped remote action (play/pause/next/back)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • Theoreticallyhugo

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Reverted some formatting changes to previous code
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (2)
docs/CONFIG.md (1)

691-697: Same wording issue as above

Please apply the same wording fix for the playerctl section.

scripts/mac-player.sh (1)

193-203: Same “newline per frame” issue as in playerctl

Use printf "\r%s " … instead of echo, otherwise the widget spams new lines.

🧹 Nitpick comments (3)
docs/CONFIG.md (1)

580-586: Grammar / clarity tweak

“Lower speeds means faster scroll” → “Lower values mean faster scrolling”.

scripts/playerctl.sh (1)

5-7: Quote path when sourcing utilities

If the path contains spaces the current unquoted source fails.

-source $current_dir/utils.sh
+source "$current_dir/utils.sh"
scripts/mac-player.sh (1)

6-6: Quote utils path for robustness

-source $current_dir/utils.sh
+source "$current_dir/utils.sh"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d85b265 and fc5efb1.

📒 Files selected for processing (4)
  • docs/CONFIG.md (2 hunks)
  • scripts/mac-player.sh (4 hunks)
  • scripts/playerctl.sh (3 hunks)
  • scripts/utils.sh (1 hunks)
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh

[warning] 255-255: Declare and assign separately to avoid masking return values.

(SC2155)

🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh

[warning] 255-255: Declare and assign separately to avoid masking return values.

(SC2155)

Added a couple fixes suggested by code rabbit
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
scripts/mac-player.sh (2)

227-230: Validate @dracula-mac-player-scroll-speed to prevent invalid sleep arguments
sleep accepts only non-negative numbers. If a user sets the option to a negative or non-numeric value the script will exit with sleep: invalid time interval. Consider clamping or defaulting:

case $SCROLL_SPEED in
  ''|*[!0-9.]*|-* ) SCROLL_SPEED=0.08 ;;
esac

251-256: Avoid SC2155 & fork-less read for cache content
Assigning and declaring in one line hides the exit status and the cat fork is unnecessary.

-  local str=$(cat "$cache_file")
+  local str
+  IFS= read -r str <"$cache_file"

Reduces process count and keeps shellcheck quiet.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc5efb1 and f829cc0.

📒 Files selected for processing (3)
  • scripts/mac-player.sh (4 hunks)
  • scripts/playerctl.sh (3 hunks)
  • scripts/utils.sh (1 hunks)
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh

[warning] 251-251: Declare and assign separately to avoid masking return values.

(SC2155)

🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/utils.sh
  • scripts/playerctl.sh
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh

[warning] 251-251: Declare and assign separately to avoid masking return values.

(SC2155)

@@ -3,8 +3,7 @@
export LC_ALL=en_US.UTF-8

current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$current_dir/utils.sh"

source $current_dir/utils.sh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Quote the sourced path to avoid breakage on paths containing spaces
Unquoted expansions break if the script is located in a directory with whitespace (e.g. “/Users/al ice/tmux”). Always quote path-like variables when sourcing or executing.

-source $current_dir/utils.sh
+source "$current_dir/utils.sh"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
source $current_dir/utils.sh
source "$current_dir/utils.sh"
🤖 Prompt for AI Agents
In scripts/mac-player.sh at line 6, the sourced path variable $current_dir is
not quoted, which can cause the script to break if the directory path contains
spaces. Fix this by enclosing $current_dir/utils.sh in double quotes when using
source, like source "$current_dir/utils.sh", to ensure the path is correctly
interpreted even with spaces.

Comment on lines +187 to 206
# Scroll the text
function scroll() {
local str=$1
local width=$2
local speed=$3

local scrolling_text=""
local i=0
local len=${#str}

for ((i = 0; i <= len; i++)); do
scrolling_text=$(slice_text "$str" "$i" "$width")
printf "\r%s " "$scrolling_text"

sleep "$speed"
done

printf "\r%s " "$scrolling_text"
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

scroll() blocks for len*speed seconds and resets every run – consider a time-based slice instead
The current loop:

  • Sleeps len times, so a 60-char title at 0.08s stalls the script for almost 5 s – longer than the default refresh rate and likely to spawn overlapping processes.
  • Restarts from index 0 on every invocation, causing a “jump” rather than seamless scroll.
  • Uses <= len; when i == len the slice starts at the terminating NUL, returning an empty string.

A safer, non-blocking alternative is to compute the start index from the current epoch modulo len, output one slice, and let tmux refresh drive the animation:

-function scroll() {
-  local str=$1
-  local width=$2
-  local speed=$3
-
-  local len=${#str}
-  for ((i = 0; i < len; i++)); do
-    printf "\r%s " "$(slice_text "$str" "$i" "$width")"
-    sleep "$speed"
-  done
-}
+scroll() {
+  local str=$1   width=$2   speed=$3
+  local len=${#str}
+
+  # Calculate frame based on time so the function prints *once* per call.
+  local frame=$(( $(date +%s%N) / $(printf '1%0.s' {1..${#speed}}) % len ))
+  echo "$(slice_text "$str" "$frame" "$width")"
+}

This keeps runtime ~ 1 ms, eliminates overlap and yields smooth, continuous scrolling.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In scripts/mac-player.sh around lines 187 to 206, the scroll() function blocks
execution for len*speed seconds and restarts the scroll from index 0 each time,
causing jumps and potential overlapping processes. To fix this, refactor
scroll() to compute the start index based on the current epoch time modulo the
string length, output only one slice per call, and remove the loop and sleep
calls. This change will make scrolling non-blocking, smooth, and continuous,
relying on external refresh timing to drive the animation.

Copy link

@coderabbitai coderabbitai bot left a 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

♻️ Duplicate comments (2)
scripts/mac-player.sh (2)

6-6: Quote $current_dir when sourcing – unresolved from previous review
The path is still unquoted, so the script breaks if its directory contains spaces.

-source $current_dir/utils.sh
+source "$current_dir/utils.sh"

187-205: scroll() blocks for len × speed seconds and restarts every call – re-implement as a non-blocking, time-based slice
Running a full loop with sleep inside a status-line script stalls tmux, spawns overlapping processes and consumes CPU. It also “jumps” back to index 0 on every refresh.

Replace the loop with a single, time-derived frame calculation:

-function scroll() {
-  local str=$1
-  local width=$2
-  local speed=$3
-
-  local scrolling_text=""
-  local i=0
-  local len=${#str}
-
-  for ((i = 0; i <= len; i++)); do
-    scrolling_text=$(slice_text "$str" "$i" "$width")
-    printf "\r%s " "$scrolling_text"
-    sleep "$speed"
-  done
-
-  printf "\r%s " "$scrolling_text"
-}
+scroll() {
+  local str=$1   width=$2   speed=$3
+  local len=${#str}
+
+  # Frame index based on current time → smooth & stateless
+  # Using nanoseconds divided by speed-in-µs to get a rolling counter.
+  local frame=$(( ( $(date +%s%N) / $(printf '%d' "$(awk 'BEGIN{printf "%d",'"$speed"'*1000000}')") ) % len ))
+
+  printf "%s" "$(slice_text "$str" "$frame" "$width")"
+}

Benefits: O(1 ms) runtime, no sleeps, no overlap, continuous scroll.

🧹 Nitpick comments (2)
scripts/mac-player.sh (2)

244-247: Quote $cache_file to survive paths with spaces

-      sliceTrack "$(cat $cache_file)" "$MAX_LENGTH" >"$cache_file"
+      sliceTrack "$(cat "$cache_file")" "$MAX_LENGTH" >"$cache_file"

250-252: Separate declaration & command substitution to silence SC2155

-  local str=$(cat "$cache_file")
+  local str
+  str=$(cat "$cache_file")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f829cc0 and a149f17.

📒 Files selected for processing (1)
  • scripts/mac-player.sh (4 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh

[warning] 251-251: Declare and assign separately to avoid masking return values.

(SC2155)

🔇 Additional comments (1)
scripts/mac-player.sh (1)

253-256: Calling the blocking scroll() here will freeze the status line until it completes
Even with a short title the loop lasts len × speed seconds (e.g. 3 s for 40 chars × 0.08 s), exceeding normal refresh intervals. Once the refactor above is applied, this concern disappears.

@Theoreticallyhugo
Copy link
Collaborator

@iberniex (the author of #343) knows the mac player best, so i'd be happy if he could check this :D

@Theoreticallyhugo
Copy link
Collaborator

i didn't think about the fact that merging @iberniex plugin improvements would mess with yours. i'm sorry for the merge conflicts.

@iberniex
Copy link
Contributor

iberniex commented Aug 14, 2025

Let me try it out :)

After he resolves the conflicts

@LinkUpGames
Copy link
Author

All good! I'll fix the conflicts later today

@LinkUpGames
Copy link
Author

@Theoreticallyhugo @iberniex I fixed the conflicts. Let me know if I'm missing something!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
scripts/mac-player.sh (2)

6-6: Quote sourced path to handle spaces safely

Unquoted path expansions will break when the script lives in a directory containing spaces.

Apply:

-source $current_dir/utils.sh
+source "$current_dir/utils.sh"

188-206: Scrolling function blocks, restarts every call, and can spawn overlapping processes

The loop sleeps len*speed seconds and reprints multiple frames per invocation. In tmux status scripts, this blocks longer than the refresh interval, leading to overlapping processes and choppy “jump to start” behavior each refresh.

Refactor to print a single frame per call, advance a persisted index, and rely on tmux refresh to animate. This keeps runtime ~ms and scales well. The step heuristics below use RATE and the configured speed to control how many chars to advance each refresh (no floating sleeps needed, compatible with macOS date).

-function scroll() {
-  local str=$1
-  local width=$2
-  local speed=$3
-
-  local scrolling_text=""
-  local i=0
-  local len=${#str}
-
-  for ((i = 0; i <= len; i++)); do
-    scrolling_text=$(slice_text "$str" "$i" "$width")
-    printf "\r%s " "$scrolling_text"
-
-    sleep "$speed"
-  done
-
-  printf "\r%s " "$scrolling_text"
-}
+function scroll() {
+  local str="$1"
+  local width="$2"
+  local speed="$3"
+
+  local len=${#str}
+  # Persist scroll index across invocations to avoid restart "jumps"
+  local idx_file="/tmp/tmux_mac_player_scroll_idx"
+  local i=0
+  if [[ -f "$idx_file" ]]; then
+    i=$(cat "$idx_file" 2>/dev/null || echo 0)
+  fi
+  # Advance by a step derived from refresh RATE and desired speed.
+  # At default RATE=5s and speed=0.08, step ~2 chars per refresh.
+  local rate="${RATE:-5}"
+  local step
+  step=$(awk -v r="$rate" -v s="$speed" 'BEGIN{ st=int(1/(r*s)); if (st<1) st=1; print st }')
+  i=$(( (i + step) % (len>0?len:1) ))
+
+  printf "%s" "$(slice_text "$str" "$i" "$width")"
+  echo "$i" > "$idx_file"
+}

Note: If you’ve added a shared scroll helper in utils.sh for playerctl, consider reusing it here to avoid duplication.

🧹 Nitpick comments (2)
scripts/mac-player.sh (2)

223-227: Redundant re-fetching of remote button options

You retrieve these options here and again inside the REMOTE_ACCESS block (Lines 239-243). Single-source them once before the conditional to avoid drift and unnecessary tmux calls.

If you keep the prefetch here, remove the duplicate reads inside the conditional.


264-270: Fix SC2155 and harden numeric comparison

Avoid declare-and-assign to preserve exit codes (ShellCheck SC2155). Also quote MAX_LENGTH in the numeric test.

-  local str=$(cat "$cache_file")
-  if [ "$SCROLL" = true ] && [ "${#str}" -ge $MAX_LENGTH ]; then
+  local str
+  str=$(cat "$cache_file")
+  if [ "$SCROLL" = true ] && [ "${#str}" -ge "$MAX_LENGTH" ]; then
     scroll "$str" "$MAX_LENGTH" "$SCROLL_SPEED"
   else
     echo "$str"
   fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a149f17 and dec42b4.

📒 Files selected for processing (2)
  • docs/CONFIG.md (2 hunks)
  • scripts/mac-player.sh (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/CONFIG.md
🧰 Additional context used
🧬 Code Graph Analysis (1)
scripts/mac-player.sh (1)
scripts/utils.sh (2)
  • slice_text (41-65)
  • get_tmux_option (3-12)
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh

[warning] 265-265: Declare and assign separately to avoid masking return values.

(SC2155)

🔇 Additional comments (1)
scripts/mac-player.sh (1)

228-231: Config surface looks good; minor note on speed granularity

Options are consistent with playerctl. Be aware that sub-second speed values won’t work with BSD sleep if used directly; the non-blocking refactor above avoids this portability issue entirely.

Comment on lines 255 to 262
if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then
local full_track

full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON")
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"

if [ "$SCROLL" = false ]; then
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
fi
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

When SCROLL=true the cache is never updated, causing stale or missing output

Inside the refresh window you compute full_track but only write to cache when SCROLL=false. On first run with SCROLL=true, cat "$cache_file" can fail; on subsequent runs the scroller may display stale text.

Write the cache in both modes: truncated when SCROLL=false, full text when SCROLL=true.

   if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then
     local full_track
     full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON")
-
-    if [ "$SCROLL" = false ]; then
-      sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
-    fi
+    if [ "$SCROLL" = true ]; then
+      printf "%s" "$full_track" > "$cache_file"
+    else
+      sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
+    fi
   fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then
local full_track
full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON")
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
if [ "$SCROLL" = false ]; then
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
fi
fi
if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then
local full_track
full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON")
if [ "$SCROLL" = true ]; then
printf "%s" "$full_track" > "$cache_file"
else
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
fi
fi
🤖 Prompt for AI Agents
In scripts/mac-player.sh around lines 255 to 262, you compute full_track only
when the cache is stale but you only write to the cache when SCROLL=false,
leaving the cache missing or stale for SCROLL=true; always write to the cache
after computing full_track: if SCROLL=false write the truncated/sliced version
to "$cache_file", otherwise write the full_track to "$cache_file" (use a safe
redirect/printf to create/overwrite the file) so downstream cat/scroller always
has current content.

Copy link
Contributor

@iberniex iberniex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is great! just address the condition issue for the cache_file and we're good. I was looking for a better way to make it fluid between renders cause after some time it disappears but it's good as it is for now.

oh I almost forgot so for the scrolling feature you need to wrap the boolean values in strings [ "$SCROLL" = "true"] and SCROLL=$(get_tmux_option "@dracula-mac-player-scroll" 'false') cause in bash everything is a string. It something I found out recently when I did the adjustments.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
scripts/mac-player.sh (2)

6-6: Quote the sourced path to avoid breakage on paths containing spaces

Unquoted $current_dir will break if the repo path has whitespace.

-source $current_dir/utils.sh
+source "$current_dir/utils.sh"

188-206: scroll() is blocking and will stall the status script; refactor to emit a single frame per call

The loop sleeps for len*speed seconds, causing the script to run for seconds per render. In tmux status, scripts should be fast and return; long-running loops can overlap and degrade UX.

If you want, I can provide a portable, non-blocking implementation that outputs one slice per invocation (driven by tmux’s refresh rate) and persists the offset between calls without relying on nanosecond time (which isn’t available on macOS date).

🧹 Nitpick comments (3)
scripts/mac-player.sh (3)

198-206: Off-by-one/duplicate frame and redundant final printf

Looping with i <= len and then printing scrolling_text again repeats the first frame. Use i < len and drop the last printf.

-  for ((i = 0; i <= len; i++)); do
+  for ((i = 0; i < len; i++)); do
     scrolling_text=$(slice_text "$str" "$i" "$width")
     printf "\r%s " "$scrolling_text"

     sleep "$speed"
   done

-  printf "\r%s " "$scrolling_text"

223-227: Remote button options: duplication with later block — consider reading once

You populate PLAY_PAUSE_BUTTON/BACK_BUTTON/NEXT_BUTTON here and again inside the “REMOTE_ACCESS == true” branch (Lines 240-242). Read them once to avoid divergence and unnecessary tmux lookups.

Proposed approach:

  • Keep this initialization here.
  • Remove the repeated get_tmux_option calls at Lines 240-242 and use the already-read values.

266-272: ShellCheck SC2155: avoid command substitution in local declaration; also faster file read

Declare then assign. Use bash’s redirection for faster reads. This also keeps return codes clearer.

-  local str=$(cat "$cache_file")
+  local str
+  str="$(< "$cache_file")"
   if [ "$SCROLL" = "true" ]; then
     scroll "$str" "$MAX_LENGTH" "$SCROLL_SPEED"
   else
     echo "$str"
   fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between dec42b4 and 8057a9c.

📒 Files selected for processing (1)
  • scripts/mac-player.sh (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
scripts/mac-player.sh (2)
scripts/playerctl.sh (1)
  • scroll (14-32)
scripts/utils.sh (2)
  • slice_text (41-65)
  • get_tmux_option (3-12)
🪛 Shellcheck (0.10.0)
scripts/mac-player.sh

[warning] 267-267: Declare and assign separately to avoid masking return values.

(SC2155)

🔇 Additional comments (1)
scripts/mac-player.sh (1)

228-231: Nice: exposes scroll toggles and speed via tmux options

Clear defaults and easy to override. Matches playerctl behavior for consistency.

Comment on lines +258 to +263

if [ "$SCROLL" = "true" ] && [ "${#str}" -ge $MAX_LENGTH ]; then
echo "$full_track" > "$cache_file"
else
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Bug: using ${#str} before str is defined; cache logic doesn’t update for SCROLL=true

str is only populated later (Line 267). This condition always evaluates with an empty str, leading to stale/missing cache entries when SCROLL=true. Also prefer printf over echo for exact writes and quote MAX_LENGTH in numeric tests.

-    if [ "$SCROLL" = "true" ] && [ "${#str}" -ge $MAX_LENGTH ]; then
-      echo "$full_track" > "$cache_file"
-    else
-      sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
-    fi
+    if [ "$SCROLL" = "true" ] && [ "${#full_track}" -ge "$MAX_LENGTH" ]; then
+      printf "%s" "$full_track" > "$cache_file"
+    else
+      sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
+    fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ "$SCROLL" = "true" ] && [ "${#str}" -ge $MAX_LENGTH ]; then
echo "$full_track" > "$cache_file"
else
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
fi
if [ "$SCROLL" = "true" ] && [ "${#full_track}" -ge "$MAX_LENGTH" ]; then
printf "%s" "$full_track" > "$cache_file"
else
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
fi
🤖 Prompt for AI Agents
In scripts/mac-player.sh around lines 258 to 263, the branch checks ${#str}
before str is defined which always evaluates as zero and causes stale/missing
cache when SCROLL=true; change the check to use the length of the actual string
variable (e.g., ${#full_track}) or move this entire cache-write block to after
str is set, quote MAX_LENGTH in the numeric comparison ([ "${#full_track}" -ge
"$MAX_LENGTH" ]), and use printf '%s' "$full_track" (or the output of
sliceTrack) instead of echo when writing to the cache file so exact content is
written.

@LinkUpGames LinkUpGames requested a review from iberniex August 17, 2025 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants