Cílem je vytvořit hodiny, které budou ukazovat zbývající čas.
date
printf
Spočítejte rozdíl dvou časů
12:34 vs 23:56
~h1=12 m1=34 h2=23 m2=56
~(( d = 60*h2 + m2 - ( 60*h1 + m1 ) ))
~printf '%02d:%02d\n' $(( d/60 )) $(( d%60 ))
11:22
Rozdíl dvou časů přepočtem na Unix timestamp
~t1=$( date -d 12:34:56 +%s )
~t2=$( date -d 23:56:12 +%s )
~(( d = t2 - t1 ))
~printf '%02d:%02d:%02d\n' \
$(( d/3600 )) $(( d%3600/60 )) $(( d%3600%60 ))
11:21:16
Rozdíl dvou časů přepočtem na Unix-timestamp bez výpočtu
~t1=$( date -d 12:34:56 +%s )
~t2=$( date -d 23:56:12 +%s )
~(( d = t2 - t1 ))
~date -d "@$d" +%T
06:21:16
~TZ= date -d "@$d" +%T
11:21:16
~timedatectl
~timedatectl show
~timedatectl list-timezones
~tzselect
~ls -l /usr/share/zoneinfo
~date +%Z
~date +%z
~sudo -i
~timedatectl set-timezone Europe/Prague
~timedatectl set-time '2021-12-31 23:59:59'
~timedatectl set-ntp 0
~timedatectl set-time '2021-12-31 23:59:59'
~exit
~sudo dpkg-reconfigure tzdata
date [MMDDhhmm[[CC]YY][.ss]]
~sudo date 1231123421
TZ
~declare -p TZ
~date
~TZ= date
~TZ=UTC date
~TZ=Europe/Prague date
~TZ= date -d "@$d" +%T
printf
printf
~printf '%(%H:%M:%S)T\n'
~printf '%(%T)T\n'
~printf '%(%T)T\n' "$t1" "$t2"
~now=$( printf '%(%s)T' )
~printf -v now '%(%s)T'
~printf '%(%T)T\n' "$now"
~end=(900 1045 1230 1415 1600 1745 1930)
~now=$( date +%k%M )
~this=-1
~while (( now >= ${end[$((++this))]} ))
~do
~ :
~done
~ends=$( date -d "${end[$this]}" +%s )
~printf -v now '%(%s)T'
~TZ= printf '%(%T)T\n' $(( ends-now ))
~PS1='[$( printf -v now "%(%s)T"
TZ= printf "%(%T)T" $(( ends-now )) )] \w> '
~PROMPT_COMMAND='printf -v now "%(%s)T"
TZ= printf -v countdown "%(%T)T" $(( ends-now ))'
~PS1='[$countdown] \w> '
\e[0;COL;COL+10m
\e[0m
~PS1='\e[0;31mtext\e[0m> '
~PS1='\e[0;37;41mtext\e[0m> '
~PS1='\[\e[0;37;41m\]text\[\e[0m\]> '
~PROMPT_COMMAND='
printf -v now "%(%s)T"
TZ= printf -v countdown "%(%T)T" $(( ends-now ))
coff=[0m con=[0m
[[ $countdown < 00:05:00 ]] && con="[0;31m"
[[ $countdown < 00:01:00 ]] && con="[0;37;41m"
(( ends-now < 0 )) && PS1="\w> "
'
~PS1='\[\e$con\][$countdown]\[\e$coff\] \w> '
ends=$( date +%s -d "$alarm" )
PS1='\[\e$con\][$countdown]\[\e$coff\] \w> '
~alias setalarm="
ends=\$( date +%s -d \"\$alarm\" )
PS1='\[\e\$con\][\$countdown]\[\e\$coff\] \w> '
"
~alarm=20:00:00
~setalarm
~/.bash_profile
nebo ~/.profile
export PROMPT_COMMAND='
printf -v now "%(%s)T"
TZ= printf -v countdown "%(%T)T" $(( ends-now ))
coff=[0m con=[0m
[[ $countdown < 00:05:00 ]] && con="[0;31m"
[[ $countdown < 00:01:00 ]] && con="[0;37;41m"
(( ends-now < 0 )) && PS1="\w> "
'
~/.bashrc
PS1='\[\e$con\][$countdown]\[\e$coff\] \w> '
alias setalarm="ends=\$( date +%s -d \"\$alarm\" )
PS1='\[\e\$con\][\$countdown]\[\e\$coff\] \w> '"
end=(900 1045 1230 1415 1600 1745 1930)
now=$( date +%k%M )
this=-1
while (( now >= ${end[$((++this))]} )); do :; done
ends=$( date -d "${end[$this]}" +%s )