Skip to content

Instantly share code, notes, and snippets.

@ze-
Last active August 29, 2015 14:06
Show Gist options
  • Save ze-/6a45002b3df3efbc359f to your computer and use it in GitHub Desktop.
Save ze-/6a45002b3df3efbc359f to your computer and use it in GitHub Desktop.
Shows remaining duration til the next nap and its wakeup. Depends on minustime.sh: https://gist.github.com/ze-/0ad16f27c769da01fec7
#!/bin/bash
wha="$(basename "${0%when*}")" # name/symlink me as napwhen.sh, buddywhen.sh, etc <any>[when][.sh]
if [[ -s ~/.${wha}whenrc ]];then source ~/.${wha}whenrc;else printf "configure me in ~/.${wha}whenrc\n" >/dev/stderr;exit 1;fi
for s in ${sleeps[@]};do sleepdates+=($(date -d "$(date +"%m/%d $s")" +%s));done
for s in ${sleeps[@]};do sleepdates+=($(date -d "$(date -d @$(($(date +%s)+(24*60*60))) +%m/%d) $s" +%s));done
for s in ${wakes[@]};do wakedates+=($(date -d "$(date +"%m/%d $s")" +%s));done
for s in ${wakes[@]};do wakedates+=($(date -d "$(date -d @$(($(date +%s)+(24*60*60))) +%m/%d) $s" +%s));done
count=0;until [[ $(date +%s) -le ${wakedates[$count]} ]];do ((count++));done
printf "sleep in $(minustime.sh "$(date)" "@${sleepdates[$count]}")\n wake in $(minustime.sh "$(date)" "@${wakedates[$count]}")\n"
# ~/.napwhenrc : config file for napwhen.sh
# 2 variables, sleeps=(<list>) and wakes=(<list>)
# where <list> are space-separated lists of times in 24h hh:mm format.
# sort them in matching order, earliest first, 1st wake goes w/ 1st sleep, etc.
sleeps=("3:20" "9:04" "13:38" "18:12" "22:46")
wakes=("4:50" "9:24" "13:58" "18:32" "23:06")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment