Skip to content

Commit 8f1a959

Browse files
Merge pull request #273 from LinkUpGames/master
Updated playerctl script to allow scrolling text
2 parents 84b6b00 + dae8e6a commit 8f1a959

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

scripts/playerctl.sh

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,59 @@
22
# setting the locale, some users have issues with different locales, this forces the correct one
33
export LC_ALL=en_US.UTF-8
44

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

8-
main()
9-
{
8+
function slice_loop() {
9+
local str="$1"
10+
local start="$2"
11+
local how_many="$3"
12+
local len=${#str}
13+
14+
local result=""
15+
16+
for ((i = 0; i < how_many; i++)); do
17+
local index=$(((start + i) % len))
18+
local char="${str:index:1}"
19+
result="$result$char"
20+
done
21+
22+
echo "$result"
23+
}
24+
25+
main() {
1026
# storing the refresh rate in the variable RATE, default is 5
1127
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
1228

13-
if ! command -v playerctl &> /dev/null
14-
then
29+
if ! command -v playerctl &>/dev/null; then
1530
exit 1
1631
fi
1732

1833
FORMAT=$(get_tmux_option "@dracula-playerctl-format" "Now playing: {{ artist }} - {{ album }} - {{ title }}")
1934
playerctl_playback=$(playerctl metadata --format "${FORMAT}")
20-
echo ${playerctl_playback}
35+
playerctl_playback="${playerctl_playback} "
36+
37+
# Adjust width of string
38+
terminal_width=25
39+
40+
# Initial start point for scrolling
41+
start=0
42+
len=${#playerctl_playback}
43+
44+
scrolling_text=""
45+
46+
for ((start = 0; start <= len; start++)); do
47+
scrolling_text=$(slice_loop "$playerctl_playback" "$start" "$terminal_width")
48+
echo -ne "\r"
49+
echo "$scrolling_text "
50+
echo -ne "\r"
51+
52+
sleep 0.08
53+
done
2154

55+
echo -ne "\r"
56+
echo "$scrolling_text "
57+
echo -ne "\r"
2258
}
2359

2460
# run the main driver

0 commit comments

Comments
 (0)