-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarktime
executable file
·33 lines (24 loc) · 890 Bytes
/
marktime
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
#!/bin/sh
###################################################################
# Script Name : Mark time (marktime)
# Description : Creates a timestamp in $XDG_DATA_HOME/marktime/[date].
# Useful to track time spend on certain activities.
# Script `subdate` calculates diff between timestamps.
# Args :
# Dependencies : cat, tail, gawk, subdate
# Variables :
# Author : Mateusz Reszka
# Email : [email protected]
###################################################################
content=$@
cur_date=$(date +'%Y-%m-%d')
cur_time=$(date +'%H:%M:%S')
data_dir=$XDG_DATA_HOME/marktime
# make sure data_dir exists
mkdir -p $data_dir
time_diff=''
file="$data_dir/$cur_date"
[ -e $file ] && prev_time=$(cat $file | tail -n 1 | awk '{print $2}') &&\
time_diff=$(subdate $prev_time $cur_time)
row="$cur_date $cur_time $content $time_diff"
echo $row >> $data_dir/$cur_date