185 lines
3.7 KiB
Bash
185 lines
3.7 KiB
Bash
#!/bin/bash
|
|
# geklaut vom linuxhotel.de
|
|
LANG=C
|
|
export BUILD="2.9.64"
|
|
set -o nounset
|
|
|
|
function banner()
|
|
{
|
|
local -A b
|
|
local -i l
|
|
local -i i
|
|
|
|
b[00]=' 000'
|
|
b[01]=' 0 0'
|
|
b[02]='0 0 0'
|
|
b[03]='0 0 0'
|
|
b[04]='0 0 0'
|
|
b[05]=' 0 0'
|
|
b[06]=' 000'
|
|
b[07]=''
|
|
b[10]=' 1'
|
|
b[11]=' 11'
|
|
b[12]=' 1 1'
|
|
b[13]=' 1'
|
|
b[14]=' 1'
|
|
b[15]=' 1'
|
|
b[16]=' 11111'
|
|
b[17]=''
|
|
b[20]=' 22222'
|
|
b[21]='2 2'
|
|
b[22]=' 2'
|
|
b[23]=' 22222'
|
|
b[24]='2'
|
|
b[25]='2'
|
|
b[26]='2222222'
|
|
b[27]=''
|
|
b[30]=' 33333'
|
|
b[31]='3 3'
|
|
b[32]=' 3'
|
|
b[33]=' 33333'
|
|
b[34]=' 3'
|
|
b[35]='3 3'
|
|
b[36]=' 33333'
|
|
b[37]=''
|
|
b[40]='4'
|
|
b[41]='4 4'
|
|
b[42]='4 4'
|
|
b[43]='4444444'
|
|
b[44]=' 4'
|
|
b[45]=' 4'
|
|
b[46]=' 4'
|
|
b[47]=''
|
|
b[50]='5555555'
|
|
b[51]='5'
|
|
b[52]='5'
|
|
b[53]=' 55555'
|
|
b[54]=' 5'
|
|
b[55]='5 5'
|
|
b[56]=' 55555'
|
|
b[57]=''
|
|
b[60]=' 66666'
|
|
b[61]='6 6'
|
|
b[62]='6'
|
|
b[63]='666666'
|
|
b[64]='6 6'
|
|
b[65]='6 6'
|
|
b[66]=' 66666'
|
|
b[67]=''
|
|
b[70]='7777777'
|
|
b[71]='7 7'
|
|
b[72]=' 7'
|
|
b[73]=' 7'
|
|
b[74]=' 7'
|
|
b[75]=' 7'
|
|
b[76]=' 7'
|
|
b[77]=''
|
|
b[80]=' 88888'
|
|
b[81]='8 8'
|
|
b[82]='8 8'
|
|
b[83]=' 88888'
|
|
b[84]='8 8'
|
|
b[85]='8 8'
|
|
b[86]=' 88888'
|
|
b[87]=''
|
|
b[90]=' 99999'
|
|
b[91]='9 9'
|
|
b[92]='9 9'
|
|
b[93]=' 999999'
|
|
b[94]=' 9'
|
|
b[95]='9 9'
|
|
b[96]=' 99999'
|
|
b[97]=''
|
|
b[:0]=' :'
|
|
b[:1]=' :::'
|
|
b[:2]=' :'
|
|
b[:3]=''
|
|
b[:4]=' :'
|
|
b[:5]=' :::'
|
|
b[:6]=' :'
|
|
b[:7]=''
|
|
for ((l=0;l<8;l++)); do
|
|
for ((i=0;i<${#1};i++)); do
|
|
printf "%-8.8s" "${b[${1:i:1}$l]}"
|
|
done
|
|
echo
|
|
done
|
|
}
|
|
|
|
function usage()
|
|
{
|
|
local base="$(basename $0)"
|
|
echo "Build: $BUILD"
|
|
echo "Usage: $base HH:MM" >&2
|
|
echo " $base +minutes" >&2
|
|
echo " $base +0" >&2
|
|
}
|
|
|
|
if [ $# -ne 1 ]; then
|
|
usage
|
|
exit 1
|
|
elif [[ $1 =~ ^([01][0-9]|2[0-3]):[0-5][0-9]$ ]]; then
|
|
dateHHMMSS="${1}:00"
|
|
elif [[ $1 =~ ^\+[0-9]+ ]]; then
|
|
dateHHMMSS=$(date -d "now $1 minutes" +%H:%M:%S)
|
|
else
|
|
usage
|
|
exit 2
|
|
fi
|
|
|
|
clear
|
|
declare -i diff
|
|
declare -i initDiff=$(($(date -d "$dateHHMMSS" +%s)-$(date +%s)))
|
|
((initDiff == 0)) && initDiff=1
|
|
declare -i lenOutDate
|
|
declare -i lenOutTime
|
|
declare outDate
|
|
declare outTime
|
|
declare -r spaces=" "
|
|
declare -r pegel="#####################################"
|
|
declare -ri lenPegel=${#pegel}
|
|
declare -ri lenSpaces=${#spaces}
|
|
declare -i posPegel
|
|
declare -i pad
|
|
|
|
while true; do
|
|
key=""
|
|
diff=$(($(date -d "$dateHHMMSS" +%s)-$(date +%s)))
|
|
|
|
outDate=$(date +"%Y-%m-%d %H:%M:%S")
|
|
outTime="${dateHHMMSS} (${diff})"
|
|
lenOutDate=${#outDate}
|
|
lenOutTime=${#outTime}
|
|
|
|
tput home
|
|
pad=$((lenSpaces-lenOutDate))
|
|
echo "${spaces:0:$((pad/2))}${outDate}${spaces:0:$((pad/2))} "
|
|
pad=$((lenSpaces-lenOutTime))
|
|
echo -e "${spaces:0:$((pad/2))}${outTime}${spaces:0:$((pad/2))} "
|
|
posPegel=$((($initDiff-$diff)*$lenPegel/$initDiff))
|
|
|
|
if (($diff >= 0 )); then
|
|
echo "[${pegel:0:$posPegel}${spaces:$((posPegel+2))}]"
|
|
else
|
|
echo "$spaces"
|
|
fi
|
|
|
|
|
|
if (( $diff == 0 )); then
|
|
tput setaf 0
|
|
elif (( $diff < 0 )); then
|
|
((diff=-diff))
|
|
tput setaf 1
|
|
elif (( $diff < 60 )); then
|
|
tput setaf 4
|
|
else
|
|
tput setaf 2
|
|
fi
|
|
|
|
echo
|
|
banner $(date -d @$diff +%M:%S)
|
|
tput setaf 0
|
|
echo -ne "\r \r" &&
|
|
read -s -t 1 -n 1 && read -s -t 3 -n 1 -p "sure? (-/n) " key && [ "$key" != "n" ] && break
|
|
done
|
|
echo -en "\r"
|