-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic_cava_colors
executable file
·51 lines (44 loc) · 1.11 KB
/
dynamic_cava_colors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
file="$(mpc --format %file% current)"
i=0
[[ -z "$file" ]] && exit 1
album_dir="${file%/*}"
LIBRARY="$MUSIC/library"
cover="$LIBRARY/$album_dir/cover.jpg"
config="$DOTFILES/cava/config"
num="$1"
[[ -z "$num" ]] && num=4
export MAGICK_OCL_DEVICE=OFF
colors="$($BIN/get_colors.py $num $cover)"
if [[ -z "$colors" ]]; then
colors='#000000
#888888'
num=2
fi
perl -pi -e 's/^gradient_count = \d+$/gradient_count = '$num'/' -- "$config"
i=1
j=1
while grep --silent "gradient_color_$i = '$color'" "$config"; do
((i++))
((j++))
continue
done
modified=0
for color in $(echo "$colors"); do
if grep --silent "gradient_color_$i" "$config"; then
perl -pi -e "s/^gradient_color_$i = '#[0-9A-Fa-f]+'$/gradient_color_$i = '$color'/" "$config"
((j++))
else
echo "gradient_color_$i = '$color'" >> $config
fi
modified=1
((i++))
done
# delete any gradient colors we didn't overwrite
if ((j == i)); then
while grep --silent "gradient_color_$j" "$config"; do
sed -i "/^gradient_color_$j =/d" "$config"
((j++))
done
fi
((modified == 1)) && pkill -USR2 cava