-
Notifications
You must be signed in to change notification settings - Fork 0
/
audacious-songchange
executable file
·134 lines (111 loc) · 3.4 KB
/
audacious-songchange
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
#!/bin/sh
VERSION="1.0.20181101"
help() { cat <</help
Executes a command file and writes a blank one in its place.
Usage: audacious-songchange [CURRENT-SONG]
Add this with audacious in Settings, Plugins, General, Song Change, starting:
audacious-songchange "%T"
Set keybindings to run commands like:
audacious-songchange --queue-stop
(this will stop audacious after the current song finishes)
audacious-songchange $VERSION, Copyright 2003+ by Adam Katz, GPLv2+
Learn more at https://github.com/adamhotep/media-scripts
/help
exit
}
version() { cat <</version
audacious-songchange $VERSION
(originally called xmms-songchange)
Copyright (C) 2003+ Adam Katz
License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
/version
exit
}
license() { cat <</license
Copyright (C) 2010+ Adam Katz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
/license
exit
}
# true only when we have all given commands
we_have() {
command -v "$@" >/dev/null 2>&1
}
# exit with given error(s)
die() {
for text in "$@"; do
echo "$text" >&2
done
exit 2
}
for DIR in .config/audacious .config/beep /.beep .config/xmms2 .xmms2 .xmms; do
DIR="$HOME/$DIR"
if [ -d "$DIR" ]; then break; fi
done
if [ ! -d "$DIR" ] || [ ! -w "$DIR" ]; then
die "Cannot locate audacious/beep/xmms2/xmms directory, aborting"
fi
CMD="${DIR##*/}" # command taken from DIR name
for CMD in "$CMD" "${CMD%2}" "${CMD}2"; do
if we_have "$CMD"; then
break
fi
done
if ! we_have "$CMD"; then
die "Cannot locate audacious/beem/xmms2/xmms command, aborting"
fi
CMDFILE="$DIR/command"
while getopts c:hLqV-: OPT; do
case "$OPT" in
(c) CMDFILE="$OPTARG" ;;
(h) help ;;
(L) license ;;
(q) QUEUE_STOP=1 ;;
(V) version ;;
(-) case "$OPTARG" in
(help) help ;;
(license) license ;;
([cq]ue*) QUEUE_STOP=1 ;;
(version) version ;;
('') break ;;
(*) die "Illegal option --$OPTARG" "Try --help" ;;
esac ;;
(\?) die "Try --help" ;;
esac
done
shift $((OPTIND-1))
# create the file if it's missing
if [ ! -e "$CMDFILE" ]; then
touch "$CMDFILE"
fi
# make executable if not already (only if we own the file)
if [ ! -x "$CMDFILE" ] && [ -O "$CMDFILE" ]; then
chmod +x "$CMDFILE"
fi
if [ 1 = "$QUEUE_STOP" ]; then
echo "$CMD --stop" >> "$CMDFILE"
exit
fi
if [ -s "$CMDFILE" ]; then
cp -p "$CMDFILE" "${CMDFILE}-prev"
fi
# run script
[ -x "$CMDFILE" ] && "$CMDFILE" || echo 'problem running script' >&2
# erase script and place the following information there instead:
echo "# now playing: $*
# $(date)
####################################################################
# This is an auto-generated file and will be overwritten after use.
# The following will be run once the above song ends:
" >"$CMDFILE"