-
Notifications
You must be signed in to change notification settings - Fork 0
/
wake-up-call.sh
executable file
·72 lines (60 loc) · 1.54 KB
/
wake-up-call.sh
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
#!/bin/bash
#
# Wake Up Call (wuc)
# A small bash script that chooses a random song of the folder you specify
# as an argument. Defaults to the current folder (using pwd)
#
# Place an entry in your cron to execute this file every morning, and you have
# your wake up call!
#
# Author: Pedro Chaves <http://github.com/pedrochaves>
# URL: http://github.com/pedrochaves/wake-up-call
#
main()
{
if [ "$1" == "-h" -o $# -eq 0 ]
then
show_help
elif [ "$1" == "-s" ]
then
stop_song
else
play_song "$1"
fi
exit 0
}
stop_song()
{
mocp -s
}
show_help()
{
echo -e
echo -e "Wake Up Call (wuc) <http://github.com/pedrochaves/wake-up-call>"
echo -e "Chooses a random song to wake you up in the morning :)"
echo -e "Works with MP3, WAV and OGG formats"
echo -e "USAGE: wuc /path/to/songs/"
echo -e
echo -e "OPTIONS"
echo -e "-h: This text and usage info"
echo -e "-s: Stops the song that is playing (shortcut to mocp -s)"
}
play_song()
{
# Finding our file
FILE=`find "${1}" -name "*.mp3" -o -name "*.wav" -o -name "*.ogg" -o -name "*.flac" -o -name "*.aac" -o -name "*.wma" | sort --random-sort | head -1`
if [ ! -f "$FILE" ]
then
echo -e "Could not find a song! Sorry :("
echo -e "If you want some help, wuc -h should do it."
exit 1
fi
# If the mocp server is not running, run it
if [ ! -f $HOME/.moc/pid ]
then
mocp -S
fi
# And finally, play our song and display some info about it
mocp -l "$FILE"
}
main $1