all repos — dotfiles @ 9dd42020ffc168010885c72a34221accd361d4d0

linux dotfiles

bin/scripts/timesheetctl (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
#!/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