-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtimelog.sh
executable file
·68 lines (58 loc) · 1.31 KB
/
gtimelog.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
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Wrapper script for gtimelog (minimal time logging application) which makes
# sure the changes in it's data/log files are commited to a git repository in
# data directory.
# by marbu, Apache License 2.0, 2019
GTIMELOG_DIR=$(/usr/bin/gtimelog --version | awk '/^Data/{print $3;}')
show_help()
{
/usr/bin/gtimelog $1
echo "Additional Commands (inplemented in the wrapper):"
echo " sh, bash Run bash shell in data directory"
echo " cal Run git cal on data directory"
}
run_bash()
{
cd "${GTIMELOG_DIR}"
bash
}
run_git_cal()
{
cd "${GTIMELOG_DIR}"
git cal
}
is_git_initialized()
{
git rev-parse --is-inside-work-tree > /dev/null
}
is_git_work_tree_clean()
{
git diff-index --quiet HEAD --
}
gtimelog_wrapper()
{
cd "${GTIMELOG_DIR}"
if ! is_git_initialized; then
git init .
fi
if ! is_git_work_tree_clean; then
git add *
git commit -m "pre gtimelog run cleanup commit"
fi
/usr/bin/gtimelog "$*"
git add *.txt && git commit -m "end of gtimelog session"
}
#
# main
#
if [[ $# = 0 ]]; then
gtimelog_wrapper
exit
fi
case $1 in
sh|shell|bash) run_bash;;
cal) run_git_cal;;
-h|--help|--help*) show_help $1;;
help) show_help -h;;
*) gtimelog_wrapper "$*";;
esac