Last active
December 14, 2015 03:59
-
-
Save ze-/5025321 to your computer and use it in GitHub Desktop.
makepoly 0.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Copyright 2010 Grant Wier <polyze at ze dAWT yi dAWT org> | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, version 3. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
# See COPYING for further details. | |
usage() { printf "Usage:\n\t$(basename $0) \ | |
-b <basetime> -n <napcount> -l <naplength> [-c <corelength>]\n\t\ | |
Makes an equiphasic polyphasic schedule.\n\t\t\ | |
-b <basetime>\tbase (start) time of schedule\n\t\t\ | |
-n <napcount>\tnumber of naps in a day\n\t\t\ | |
-l <naplength>\tlength of each nap\n\t\t\ | |
-c <corelength>\tadd a core <corelength> long\n\t\ | |
Accepts minutes or hh:mm for all arguments.\n\t\ | |
First nap or core starts at <basetime>.\n" >/dev/stderr | |
exit 1 | |
} | |
mt() { | |
printf "%02d:%02d" $(($1/60)) $(($1%60)) | |
} | |
[[ $# -lt 6 ]] && usage | |
while getopts b:n:l:c: OPT;do | |
[[ -n "${OPTARG//[0-9:]}" || -z "${OPTARG//:}" ]] && { echo \ | |
"*** Invalid argument to $OPT: $OPTARG" >/dev/stderr;usage ; } | |
if [[ "$OPTARG" != "${OPTARG/:}" ]];then | |
hour=${OPTARG/:*} | |
min=${OPTARG/*:} | |
OPTARG=$((${hour:-0}*60+${min:-0})) | |
fi | |
case "$OPT" in | |
b) base_time=$OPTARG ;; | |
n) nap_count=$OPTARG ;; | |
l) nap_length=$OPTARG ;; | |
c) core_length=$OPTARG ;; | |
?) usage ;; | |
esac | |
done | |
[[ $base_time && $nap_count && $nap_length ]] || usage | |
[[ $base_time -gt 1439 ]] && { echo "*** Base time out of range: $(mt $base_time)"\ | |
>/dev/stderr; usage ; } | |
wake_length=$(((1440-(core_length+nap_count*nap_length))/\ | |
(core_length>0?nap_count+1:nap_count))) | |
nap_num=1 | |
if [[ $core_length ]];then | |
printf "Core: $(mt $base_time)-" | |
base_time=$(((base_time+core_length)>=1440?base_time-1440:base_time)) | |
printf "$(mt $((base_time+core_length)))\n" | |
base_time=$((base_time+core_length+wake_length)) | |
fi | |
while [[ $nap_num -le $nap_count ]];do | |
base_time=$((base_time>=1440?base_time-1440:base_time)) | |
printf "Nap $nap_num: $(mt $base_time)-" | |
base_time=$(((base_time+nap_length)>=1440?base_time-1440:base_time)) | |
printf "$(mt $((base_time+nap_length)))\n" | |
base_time=$((base_time+wake_length+nap_length)) | |
nap_num=$((nap_num+1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment