You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

#!/usr/bin/env bash
function round() {
echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
}
function drawBar(){
local percent=$1;
for i in {1..10}; do
local boxPercent=$(($i*10))
if [ "$boxPercent" -lt "$percent" ]; then
echo -n "■"
elif [ "$boxPercent" -eq "$percent" ]; then
echo -n "■"
elif [ "$(($boxPercent-10))" -lt "$percent" ]; then
echo -n "▣"
else
echo -n "□"
fi
done
}
function getTimer(){
if [ -e "$HOME/timer" ]; then
local humanDuration=$(head -n 1 "$HOME/timer")
# All these dates are in seconds since the epoch
local duration=$(( $(date -d "now + $humanDuration" '+%s') - $(date '+%s') ))
local startTime=$(stat --format="%Y" "$HOME/timer")
local endTime=$(( $startTime + $duration ))
local currentTime=$(date '+%s')
if [ $endTime -gt $currentTime ]; then
local percentage=$(echo " ( ( $currentTime - $startTime ) * 100 ) / ( $endTime - $startTime ) " | bc )
echo -n "$percentage% "
echo $(drawBar $percentage)
fi
fi
}
time=$(date '+%T')
date=$(date '+%A %d %B %Y')
timer="$(getTimer)"
notify-send "$time" "$date\n$timer$1"