-
Notifications
You must be signed in to change notification settings - Fork 0
/
workhours.sh
executable file
·55 lines (47 loc) · 1.84 KB
/
workhours.sh
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
#!/bin/env bash
time=$(date +'%d %m %y %H %M %S')
filetimestamp=$(date +'%m')
foldertimestamp=$(date +'%Y')
filepath="$HOME/Documents/Worktime"
previousfile=$((filetimestamp-1))
previousmonth=$((foldertimestamp-1))
if [[ ! -d "$filepath/$foldertimestamp" ]]; then
archivepath="$filepath/$foldertimestamp"
mkdir -p "$archivepath"
fi
if [[ -f "$filepath/$filetimestamp.dat" ]]; then
timesheet="$filepath/$filetimestamp.dat"
elif [[ ! -f "$filepath/$filetimestamp.dat" ]]; then
touch "$filepath/$filetimestamp.dat"
if [[ "$previousfile" = "0" ]]; then
if [[ "$previousmonth"="1" ]] || [[ "$previousmonth"="3" ]] || [[ "$previousmonth"="5" ]] || [[ "$previousmonth"="7" ]] || [[ "$previousmonth"="8" ]] || [[ "$previousmonth"="10" ]]; then
previousfile="31"
$previousmonth-=1
elif [[ "$previousmonth"="4" ]] || [[ "$previousmonth"="6" ]] || [[ "$previousmonth"="9" ]] || [[ "$previousmonth"="11" ]]; then
previousfile="30"
$previousmonth-=1
elif [[ "$previousmonth"="2" ]]; then
previousfile="28"
$previousmonth-=1
fi
fi
if [[ "$previousmonth"=0 ]]; then
previousfile="31"
previousmonth="12"
fi
mv "$filepath/$previousfile.dat" "$archivepath/"
timesheet="$filepath/$filetimestamp.dat"
fi
lastreg=$( awk '{w=$1} END{print w}' "$timesheet" )
# TODO create new file each month
# TODO move to archive after month is finished
# TODO add check for missing out the month before
if [[ "$lastreg" = "" ]]; then
printf '%s\n' "in $time" >> "$timesheet"
elif [[ ! "$lastreg" = "in" ]]; then
printf '%s\n' "in $time" >> "$timesheet"
python "$HOME/Scripts/Programs/assorted-scripts/workhours_disp.py" -f "$timesheet"
elif [[ "$lastreg" = "in" ]]; then
( printf '%s\n' "ut $time" >> "$timesheet" )
fi
#bat "$timesheet"