~anjan/sxmo-userscripts

ref: 0541bd1d23e30cac3b71f06b65994675bde9a00c sxmo-userscripts/musicpd.sh -rw-r--r-- 3.3 KiB
0541bd1dBaroque0 improved my_photos.sh with a thumbnails view (in practice two separate windows, one for the thumbnails and one for the picture.). also enforced that rotation, using < and > be automatically saved in place of original image. (requires libjpeg-turbo-tools for jpegtran) 4 months ago
                                                                                
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env sh
# shellcheck disable=SC2154

# shellcheck disable=SC1090
. "$(which sxmo_common.sh)"

prompt() {
	dmenu -i -c -l 13 "$@"
}

set -e

loadmarkers() {
	if ! MPC="$(mpc)"; then
		MARKERS="disconnected"
		return
	fi

	repeat="$(printf %s "$MPC" | grep -qF "repeat: on" && printf "r" || printf "" )"
	random="$(printf %s "$MPC" | grep -qF "random: on" && printf "z" || printf "" )"
	single="$(printf %s "$MPC" | grep -qF "single: on" && printf "s" || printf "" )"
	consume="$(printf %s "$MPC" | grep -qF "consume: on" && printf "c" || printf "" )"
	MARKERS="[$repeat$random$single$consume]"
}

playlistloop() {
	while true ;
	do
		CHOICE="$(
			mpc playlist |
			xargs -0 printf "$icon_ret Return\n%s" |
			prompt -p "Playlist"
		)"

		case "$CHOICE" in
			"$icon_ret Return")
				break
				;;
			*)
				echo "$CHOICE" \
					| awk -F " - " '{ print $2 }' \
					| xargs -I{} mpc searchplay "{}"
				;;
		esac
	done
}

browseloop() {
	path=""
	while true ;
	do
		[ "$path" = "." ] && path=
		CHOICE="$(
			mpc ls "$path" |
			xargs -0 printf "$icon_ret Return\n..\n*\n%s" |
			prompt -p "Browse"
		)"

		case "$CHOICE" in
			"$icon_ret Return")
				break
				;;
			"*")
				mpc add "$path"
				;;
			"..")
				path="$(dirname "$path")"
				;;
			*"."*)
				mpc add "$CHOICE"
				;;
			*)
				path="$CHOICE/"
				;;
		esac
	done
}

optionloop() {
	while true; do
		loadmarkers

		CHOICES="
			$icon_ret Return
			$icon_rol Repeat      ^ mpc repeat
			$icon_ror Single      ^ mpc single
			$icon_sfl Random      ^ mpc random
			$icon_shr Consume     ^ mpc consume
		"

		PICKED="$(
			echo "$CHOICES" |
			xargs -0 echo |
			sed '/^[[:space:]]*$/d' |
			awk '{$1=$1};1' |
			cut -d'^' -f1 |
			prompt -p "Options $MARKERS"
		)"

		case "$PICKED" in
			"$icon_ret Return")
				break
				;;
			*)
				CMD="$(
					printf '%b' "$CHOICES" |
					grep -m1 -F "$PICKED" |
					cut -d'^' -f2 |
					sed '/^[[:space:]]*$/d' |
					awk '{$1=$1};1'
				)"
				sh -c "$CMD"
				;;
		esac
	done
}

mpdtoggleline() {
	command -v mpd > /dev/null || return
	pgrep mpd > /dev/null \
		&& printf "%s Stop MPD ^ mpd --kill" "$icon_zzz" \
		|| printf "%s Start MPD ^ mpd" "$icon_pwr"
	printf " && sleep 1"
}

mainloop() {
	while true; do
		loadmarkers
		CHOICES="
			$icon_pau Toggle      ^ mpc toggle
			$icon_stp Stop        ^ mpc stop
			$icon_nxt Next        ^ mpc next
			$icon_prv Previous    ^ mpc prev
			$icon_lst Playlist
			$icon_dir Browse
			$icon_cfg Options
			$icon_spk Audio       ^ sxmo_appmenu.sh audioout
			$icon_bth Bluetooth   ^ sxmo_bluetoothmenu.sh
			$icon_rld Update      ^ mpc update
			$icon_cls Clear Queue ^ mpc clear
			$(pgrep mpd > /dev/null && printf "%s Stop MPD ^ mpd --kill" "$icon_zzz" || printf "%s Start MPD ^ mpd" "$icon_pwr") && sleep 1
			$icon_ret Close Menu
		"

		PICKED="$(
			echo "$CHOICES" |
			xargs -0 echo |
			sed '/^[[:space:]]*$/d' |
			awk '{$1=$1};1' |
			cut -d'^' -f1 |
			prompt -p "Music $MARKERS"
		)"

		case "$PICKED" in
			"$icon_ret Close Menu")
				break
				;;
			"$icon_lst Playlist")
				playlistloop
				;;
			"$icon_dir Browse")
				browseloop
				;;
			"$icon_cfg Options")
				optionloop
				;;
			*)
				CMD="$(
					printf '%b' "$CHOICES" |
					grep -m1 -F "$PICKED" |
					cut -d'^' -f2 |
					sed '/^[[:space:]]*$/d' |
					awk '{$1=$1};1'
				)"
				sh -c "$CMD"
				;;
		esac
	done
}

mainloop