-
Notifications
You must be signed in to change notification settings - Fork 0
/
_cmus,--.control.music.player
executable file
·165 lines (161 loc) · 5.56 KB
/
_cmus,--.control.music.player
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env sh
# author: gotbletu (@youtube|github|odysee)
# https://www.youtube.com/user/gotbletu
# desc: control cmus via fzf
# depend: fzf cmus coreutils awk notify-send
# allow notify-send to work in XFCE4
# xfce4-notifyd > applications > notify-send > [ ] mute application
track_time() {
duration_total="$(cmus-remote -Q | awk '/duration / {print $2}')"
duration_min=$((duration_total / 60))
duration_sec=$((duration_total % 60))
position_total="$(cmus-remote -Q | awk '/position / {print $2}')"
position_min=$((position_total / 60))
position_sec=$((position_total % 60))
}
mylist() {
cat <<EOF
random
queue
status
next
previous
play-pause
stop
shuffle-toggle
repeat-toggle
repeat-current
aaa-toggle
seek-forward +10s
seek-backward -10s
seek-forward +1m
seek-backward -1m
volume-up +10
volume-down -10
volume 5
volume 10
volume 15
volume 20
volume 25
volume 30
volume 35
volume 40
volume 45
volume 50
volume 55
volume 60
volume 65
volume 70
volume 75
volume 80
volume 85
volume 90
volume 95
volume 100
EOF
}
export FZF_DEFAULT_OPTS="-e -i --layout=reverse --scroll-off=5 --tiebreak=index \
--bind 'ctrl-x:execute:cmus-remote --pause >/dev/tty' \
--bind 'ctrl-s:execute:cmus-remote --stop >/dev/tty' \
--bind 'alt-n:execute:cmus-remote --next --play >/dev/tty' \
--bind 'alt-p:execute:cmus-remote --prev --prev --play >/dev/tty' \
--bind 'ctrl-r:execute:cmus-remote --clear --queue ; cmus-remote --queue \"\$(shuf -n 1 < ~/.cmus/lib.pl)\" ; cmus-remote --next --play >/dev/tty' \
--header 'C-x:playpause C-s:stop A-n:next A-p:prev C-r:random C-j/k/n/p:navigate'
"
selected="$(mylist | fzf --info=hidden --prompt="cmus: ")"
[ -z "$selected" ] && exit
case $selected in
random)
cmus-remote --clear --queue
cmus-remote --queue "$(shuf -n 1 < ~/.cmus/lib.pl)"
cmus-remote --next --play
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/ artist / || /album / || /title / || /date/ {print substr($0, index($0,$2)) }')"
;;
queue)
selected="$(fzf -m -d / --with-nth '-2..' --info=inline --prompt="cmus >>> queue song(s): " < ~/.cmus/lib.pl )"
[ -z "$selected" ] && exit
cmus-remote --clear --queue # clear cmus queue
echo "$selected" | while read -r line ; do cmus-remote --queue "$line" ; done # add songs to queue playlist
cmus-remote --next --play # play queued song
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/ artist / || /album / || /title / || /date/ {print substr($0, index($0,$2)) }')"
;;
status)
notify-send -t 10000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/ artist / || /album / || /title / || /date/ || /shuffle/ || /vol_/ || /repeat/ {print substr($0, index($0,$2)) }')"
;;
next)
cmus-remote --next --play
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/ artist / || /album / || /title /|| /date/ {print substr($0, index($0,$2)) }')"
;;
previous)
cmus-remote --prev --prev --play
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/ artist / || /album / || /title /|| /date/ {print substr($0, index($0,$2)) }')"
;;
play-pause)
cmus-remote --pause
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/ artist / || /album / || /title /|| /date/ {print substr($0, index($0,$2)) }')"
;;
stop)
cmus-remote --stop
;;
shuffle-toggle)
cmus-remote --shuffle # tracks, albums, off
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/shuffle/ {print substr($0, index($0,$2)) }')"
;;
repeat-toggle)
cmus-remote --repeat
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/repeat / {print substr($0, index($0,$2)) }')"
;;
repeat-current)
cmus-remote -C "toggle repeat_current"
if [ "$(cmus-remote -Q | awk '/repeat_current/ {print $3}')" = "true" ]; then
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q \
| awk '/repeat_current/ || / artist / || /album / || /title / || /date/ {print substr($0, index($0,$2)) }')"
else
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q | awk '/repeat_current/ {print substr($0, index($0,$2)) }')"
fi
;;
aaa-toggle)
cmus-remote -C "toggle aaa_mode" # toggle artist, album, all
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q | awk '/aaa_mode/ {print substr($0, index($0,$2)) }')"
;;
"seek-forward +10s")
cmus-remote --seek +10
track_time
notify-send -t 5000 --icon=info "cmus" "$position_min:$position_sec / $duration_min:$duration_sec"
;;
"seek-backward -10s")
cmus-remote --seek -10
track_time
notify-send -t 5000 --icon=info "cmus" "$position_min:$position_sec / $duration_min:$duration_sec"
;;
"seek-forward +1m")
cmus-remote --seek +1m
track_time
notify-send -t 5000 --icon=info "cmus" "$position_min:$position_sec / $duration_min:$duration_sec"
;;
"seek-backward -1m")
cmus-remote --seek -1m
track_time
notify-send -t 5000 --icon=info "cmus" "$position_min:$position_sec / $duration_min:$duration_sec"
;;
"volume-up +10")
cmus-remote --volume +10%
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q | awk '/vol_/ {print substr($0, index($0,$2)) }')"
;;
"volume-down -10")
cmus-remote --volume -10%
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q | awk '/vol_/ {print substr($0, index($0,$2)) }')"
;;
"volume "*)
cmus-remote --volume "$(echo "$selected" | cut -d ' ' -f2)"%
notify-send -t 5000 --icon=info "cmus" "$(cmus-remote -Q | awk '/vol_/ {print substr($0, index($0,$2)) }')"
;;
esac