all repos — dotfiles @ ab1de17aea72b6ccc8d5b9c62bac38fc4c2d3125

linux dotfiles

update timesheetctl
Prithu Goswami pg@prithu.dev
Sat, 13 Jul 2024 18:38:38 +0530
commit

ab1de17aea72b6ccc8d5b9c62bac38fc4c2d3125

parent

a779bb5b6a1eac31c26474c5fafa7ff826bef8d2

1 files changed, 22 insertions(+), 12 deletions(-)

jump to
M bin/scripts/timesheetctlbin/scripts/timesheetctl

@@ -1,30 +1,41 @@

#!/bin/sh +set -x ts_dir="$HOME/docs/org/2-notes/comono/timesheets" -ts_file="$ts_dir/timesheet-`date +%Y%m`.csv" + +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}')" - if [[ -f $ts_file ]] + project=${1:-"inspera"} + file=$(get_file $project) + if [[ -f $file ]] then - echo "Error: File exists - $ts_file" 1>&2 + 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; ; inspera;\n" $i `date +%m-%Y` >> $ts_file + printf "%02d-%s; ;$project;\n" $i `date +%m-%Y` >> $file done } edit_timesheet() { - if [[ ! -f $ts_file ]] + project=${1:-"inspera"} + file=$(get_file $project) + if [[ ! -f $file ]] then - make_timesheet + make_timesheet $project fi - vim $ts_file + vim $file } ts_summary() { - hr_spent="$(awk -F';' '{ sum+=$2 } END {print sum}' $ts_file)" + 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)"

@@ -36,11 +47,10 @@ }

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