all repos — dotfiles @ ab1de17aea72b6ccc8d5b9c62bac38fc4c2d3125

linux dotfiles

bin/scripts/timesheetctl

#!/bin/sh
set -x
ts_dir="$HOME/docs/org/2-notes/comono/timesheets"

get_file() {
   echo "$ts_dir/timesheet-$1-`date +%Y%m`.csv"
}

make_timesheet() {
    last_day="$(cal `date '+%m %Y'` | head -n -1 | tail -1 | awk '{print $NF}')"
    project=${1:-"inspera"}
    file=$(get_file $project)
    if [[ -f $file ]]
    then
        echo "Error: File exists - $file" 1>&2
        exit
    fi
    # for i in $(seq -f %02g 1 $last_day)
    for((i=01;i<=last_day;i++))
    do
        printf "%02d-%s;   ;$project;\n" $i `date +%m-%Y` >> $file
    done
}

edit_timesheet() {
    project=${1:-"inspera"}
    file=$(get_file $project)
    if [[ ! -f $file ]]
    then
        make_timesheet $project
    fi
    vim $file
}

ts_summary() {
    project=${1:-"inspera"}
    file=$(get_file $project)
    hr_spent="$(awk -F';' '{ sum+=$2 } END {print sum}' $file)"
    last_day="$(cal `date '+%m %Y'` | head -n -1 | tail -1 | awk '{print $NF}')"
    days_left="$(expr $last_day - `date +%d`)"
    hr_left="$(expr 136 - $hr_spent)"
    avg_hrs="$(awk "BEGIN {printf \"%.2f\", $hr_left/$days_left;exit}")"
    echo -e "Hours put in:\t\t$hr_spent"
    echo -e "Days Left:\t\t$days_left"
    echo -e "\x1b[48;5;238mAvg. Hours to put in:   \x1b[1m$avg_hrs\x1b[0m"
}

option="$1"
case "$option" in
    edit|e) edit_timesheet $2
        ;;
    make|m) make_timesheet $2
        ;;
    summary|s) ts_summary $2
        ;;
esac