tChange to POSIX compatible shell - exercise_time - announce workout exercises with notifications and speech synth
 (HTM) git clone git://src.adamsgaard.dk/exercise_time
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit afd67f79d5687a0a797a6302edd75e84eacc8c6c
 (DIR) parent ffe55fd0726787ac90371852875018429068994f
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Mon, 17 Jun 2019 09:03:03 +0200
       
       Change to POSIX compatible shell
       
       Diffstat:
         M exercise_time.sh                    |      52 ++++++++++++++++----------------
       
       1 file changed, 26 insertions(+), 26 deletions(-)
       ---
 (DIR) diff --git a/exercise_time.sh b/exercise_time.sh
       t@@ -1,4 +1,4 @@
       -#!/bin/bash
       +#!/bin/sh
        
        # IT'S EXERCISE TIME!
        # Requires the `festival` speech synthesizer if on Linux and/or `libnotify-bin`
       t@@ -21,45 +21,45 @@ WAITSECS=120
        # Announce via speech synth (0: No, 1: Yes)
        SPEECHSYNTH=1
        
       -function usage {
       +usage() {
            echo "Usage: ${0##*/} <SETS> <EXERCISE>"
            echo "Example: For three sets of ten pushups, use:"
            echo "   $0 3 'Do ten push ups'"
        }
        
       -if [ "$1" == "-h" ]; then
       +if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
            usage
       -    exit
       +    exit 0
        fi
        
        # stop mpd if it is running
       -#mpc pause &> /dev/null
       +#mpc pause > /dev/null 2>&1
        
        UNAMESTR="$(uname)"
        
        # announce exercise the specified number of times
        
        # Only send notification at work
       -if [[ "$UNAMESTR" == 'Darwin' ]]; then
       +if [ "$UNAMESTR" = "Darwin" ]; then
            IP=$(/sbin/ifconfig | grep 10.9.62) # Sayre Hall
        else
            IP=$(ip addr | grep 192.168.0)
        fi
        
       -for ((i=0; i<$1; i++)); do
       +for i in 0.."$1"; do
        
            announcement="It's exercise time! $2"
        
            # Send message to notification daemon if computer is plugged in at my office
            # desk
       -    if [[ $IP ]]; then
       +    if [ -n "$IP" ]; then
        
                # OS X
       -        if [[ "$UNAMESTR" == 'Darwin' ]]; then
       +        if [ "$UNAMESTR" = "Darwin" ]; then
                    osascript -e "display notification \"$2\" with title \"It's exercise time\""
        
                # Linux
       -        elif [[ "$UNAMESTR" == 'Linux' ]]; then
       +        elif [ "$UNAMESTR" = "Linux" ]; then
                    notify-send "$announcement"
                fi
            fi
       t@@ -68,38 +68,38 @@ for ((i=0; i<$1; i++)); do
            if [ $SPEECHSYNTH -eq 1 ]; then
        
                # OS X
       -        if [[ "$UNAMESTR" == 'Darwin' ]]; then
       -            if [[ $IP ]]; then
       +        if [ "$UNAMESTR" = "Darwin" ]; then
       +            if [ -n "$IP" ]; then
                        say "$announcement"
                    fi
        
                # Linux
       -        elif [[ "$UNAMESTR" == 'Linux' ]]; then
       +        elif [ "$UNAMESTR" = "Linux" ]; then
        
                    playingmusic=0
        
       -            if [[ $IP ]]; then
       -                if command -v mpc &>/dev/null; then
       -                    if [[ "$(mpc | grep playing)" ]]; then
       -                        mpc pause &> /dev/null
       -                        sleep 2
       -                        playingmusic=1
       -                    fi
       -                fi
       -                if command -v festival &>/dev/null; then
       +            if [ -n "$IP" ]; then
       +                # if command -v mpc >/dev/null 2>&1; then
       +                #     if [ "$(mpc | grep playing)" ]; then
       +                #         mpc pause > /dev/null 2>&1
       +                #         sleep 2
       +                #         playingmusic=1
       +                #     fi
       +                # fi
       +                if command -v festival >/dev/null 2>&1; then
                            echo "$announcement" | festival --tts
                        fi
       -                if command -v mpc &>/dev/null; then
       -                    if [[ $playingmusic -eq 1 ]]; then
       +                if command -v mpc >/dev/null 2>&1; then
       +                    if [ $playingmusic -eq 1 ]; then
                                sleep 2
       -                        mpc play &> /dev/null
       +                        mpc play > /dev/null 2>&1
                            fi
                        fi
                    fi
                fi
            fi
        
       -    if [[ $i -lt $(($1 - 1)) ]]; then
       +    if [ "$i" -lt "$(echo "$1" - 1 | bc -l)" ]; then
                sleep $WAITSECS
            fi
        done