just-play-something: reindent, shellcheck

This commit is contained in:
Matteo Cypriani 2018-04-11 21:46:47 +02:00
parent e28443a12e
commit ff3da6cdee
1 changed files with 11 additions and 10 deletions

View File

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