All pastes #1911373 Raw Edit

makepoly.sh

public shellscript v1 · immutable
#1911373 ·published 2010-07-29 23:25 UTC
rendered paste body
#!/bin/bashfunction 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 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> time.\n" >/dev/stderrexit 1}function mt() {  printf "%02d:%02d" $(($1/60)) $(($1%60))}[ $# -lt 6 ] && usagewhile getopts b:n:l:c: OPT;do  [ -n "${OPTARG//[0-9:]}" -o -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 ;;  esacdone[ $base_time -a $nap_count -a $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=1if [ $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))fiwhile [ $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