Lots of bin changes

This commit is contained in:
Jonathan Hodgson 2020-01-04 13:21:05 +00:00
parent 0f80079368
commit 55a7d2da4f
12 changed files with 258 additions and 44 deletions

View file

@ -1,3 +1,52 @@
#!/usr/bin/env bash
notify-send "$(date '+%T')" "$(date '+%A %d %B %Y')"
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"