#!/usr/bin/env bash # Author: Lilian BESSON, (C) 2016-oo # Email: Lilian.BESSON[AT]ens-cachan[DOT]fr # Date: 08-01-2017. # Web: https://bitbucket.org/lbesson/bin/src/master/Wait # # Wait: a script to display a nice waiting bar (like sleep, but pretty). # Idea and most of the code is from http://stackoverflow.com/a/34708674 # # Usage: Wait "time" "Message" [french] # # Example: # $ Wait "30 min" "Sors le plat du four." french # $ Wait "20 min" "Call your dad." # # Licence: MIT Licence (http://lbesson.mit-license.org). version="0.1" # http://redsymbol.net/articles/unofficial-bash-strict-mode/ set -euo pipefail function printhelp(){ cat << EOF Wait: a script to display a nice waiting bar (like sleep, but pretty). Usage: Wait "time" "Message" [french] Example: $ Wait "30 min" "Sors le plat du four." french. $ Wait "20 min" "Call your dad." EOF exit 0 } [ -x ~/.color.sh ] && . ~/.color.sh # Add here options JUSTVERSION=false for i in "$@"; do case "$i" in --version ) JUSTVERSION=true shift ;; -h | --help ) printhelp ;; esac done if [ "${#@}" -lt 2 ]; then printhelp; fi # Copyrights and options echo -e "${green}$0 v${version} : copyright (C) 2017 Lilian Besson" echo -e " You can find it online (https://bitbucket.org/lbesson/bin/src/master/Wait)" echo -e " This is free software, and you are welcome to redistribute it under certain conditions." echo -e " This program comes with ABSOLUTELY NO WARRANTY; for details see http://lbesson.mit-license.org${white}" ${JUSTVERSION} && exit 1 # Script # Configuration for dialog INIT=$(/bin/date "+%s") NOW=$INIT FUTURE=$(/bin/date -d "$1" "+%s") [ "$FUTURE" -a "$FUTURE" -eq "$FUTURE" ] || exit DIFF=$(( FUTURE - INIT )) # Feed to the dialog command while [ "$INIT" -le "$FUTURE" -a "$NOW" -lt "$FUTURE" ]; do NOW=$(/bin/date "+%s") STEP=$(( NOW - INIT )) SLEFT=$(( FUTURE - NOW )) MLEFT=$(echo "scale=2; $SLEFT/60" | bc -l) TEXT="$SLEFT seconds left ($MLEFT minutes)"; TITLE="Waiting $1: $2" sleep 1s PTG=$(echo "scale=0; $STEP * 100 / $DIFF" | bc -l) echo "$PTG" | dialog --title "$TITLE" --gauge "$TEXT" 7 72 done # Configuration for the notify-send and espeak commands language="${3:-english}" title="Wait - Bash script" if [ "$language" == "french" ]; then title="Wait - Script pour attendre" fi if [ "$2" == "" ]; then msg="Wait before printing this message: $1" audio="Done" if [ "$language" == "french" ]; then msg="En attente avant d'afficher ce message : $1" audio="Terminé" fi else msg="Done: $2" audio=$2 if [ "$language" == "french" ]; then msg="Terminé : $2" fi fi notify-send --icon=stock_appointment-reminder-excl "$title" "$msg" for i in $(seq 1 3); do espeak -s 130 -v "$language" "$audio" sleep 0.3 done clear # End of Wait