Browse Source

just-play-something: reindent, shellcheck

master
Matteo Cypriani 4 years ago
parent
commit
ff3da6cdee
  1. 21
      audio/just-play-something.sh

21
audio/just-play-something.sh

@ -19,28 +19,29 @@
#set -x
TIME="/usr/bin/time 2>&1"
# Returns a random number between 1 and its first argument
random()
{
MAX=$1
RAND=0`(echo $$ ; /usr/bin/time ps 2>&1 ; date) | md5sum | sed 's/[a-z]//g' | sed -r 's/(.{8}).*/\1/'`
expr $RAND % $MAX + 1
max=$1
rand=0$( (echo $$ ; /usr/bin/time ps 2>&1 ; date) \
| md5sum | sed 's/[a-z]//g' | sed -r 's/(.{8}).*/\1/')
echo $((rand % max + 1))
}
# If we can't reach the server, restart it
if ! mpc >/dev/null 2>&1 ; then
/etc/init.d/mpd restart
/etc/init.d/mpd restart
fi
# If the playlist is empty, add a random album to the playlist
if [ "$(mpc playlist 2>/dev/null)" = "" ] ; then
NB_ALBUMS=`mpc list Album | wc -l`
RAND_ALBUM_NUM=`random $NB_ALBUMS`
RANDOM_ALBUM=`mpc list Album | sed -n ${RAND_ALBUM_NUM}p`
mpc findadd Album "$RANDOM_ALBUM"
NB_ALBUMS=$(mpc list Album | wc -l)
RAND_ALBUM_NUM=$(random "$NB_ALBUMS")
RANDOM_ALBUM="$(mpc list Album | sed -n "${RAND_ALBUM_NUM}p")"
mpc findadd Album "$RANDOM_ALBUM"
fi
# Start playing or toggle pause
mpc toggle >/dev/null 2>&1
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

Loading…
Cancel
Save