blob: 0e3210974fe5359d95f2f4254e98ce975bb8e55e (
plain) (
blame)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#!/bin/bash
#
## Wrapper script for quart
#
## Takes care of ~/.quart.d
#
## .quart.d
## |-- archive
## | |-- 190706_Saturday_220700.org
## | |-- 190707_Sunday_220701.org
## |-- today.org
#
##
## Initialize values
##
#
ED="${EDITOR:-emacs -nw}"
QHOME="${QUART_HOME:-$HOME/.quart.d}"
ARCHIVE="$QHOME"/archive
TODAY_FILE="$QHOME"/today.org
DATE_CMD="date +%y%m%d_%A_%H%m%S"
if [[ -z $(which quart) ]]; then
echo "quart is not installed"
exit 1
fi
QUART_CMD=$(which quart)
function archive {
if [[ ! -d "$ARCHIVE" ]]; then
echo "archive directory does not exist"
exit 1
fi
if [[ -f "$TODAY_FILE" ]]; then
mv "$TODAY_FILE" "$ARCHIVE/$($DATE_CMD)"
return 1
fi
return 0
}
function make_today {
if [[ ! -d "$QHOME" ]]; then
echo "quart home directory does not exist"
exit 1
fi
cat > "$TODAY_FILE" << EOF
#+START: 9:00
# quart schedule created at $(date "+%A %d of %B the year of our lord %Y")
# Avaliable task flags:
# ! Urgent, ? Maybe, @ External
# Use `=` to signal a task repeat
EOF
}
function edit_today {
if [[ ! -f "$TODAY_FILE" ]]; then
echo "run new first"
exit 1
fi
$ED "$TODAY_FILE"
}
function summary_today {
if [[ ! -f "$TODAY_FILE" ]]; then
return 0
fi
"$QUART_CMD" "$TODAY_FILE" -s
}
function make_qhome {
if [[ -d "$QHOME" ]]; then
echo "QUART_HOME already exists in $QHOME"
else
mkdir "$QHOME"
echo "QUART_HOME initialized in $QHOME"
fi
if [[ -d "$ARCHIVE" ]]; then
echo "archive directory already exists"
else
mkdir "$ARCHIVE"
echo "archive directory created"
fi
}
if [ $# -lt 1 ]; then
if [[ ! -d "$QHOME" ]]; then
echo "run init first"
exit 1
fi
if [[ ! -f "$TODAY_FILE" ]]; then
echo "run new first"
exit 1
fi
echo -e "Current schedule:\n"
"$QUART_CMD" "$TODAY_FILE" -s
exit 0
fi
if [[ "$1" == "-" ]]; then
shift
"$QUART_CMD" "$TODAY_FILE" $@
exit $?
fi
case $1 in
init|i)
make_qhome
exit 0
# create ~/.quart.d director structure
;;
new|n)
shift
archive
make_today
edit_today
summary_today
exit 0
# backup the old schedule and create a new one
;;
edit|e)
shift
edit_today
summary_today
exit 0
# edit the current schedule
;;
remove|rm)
shift
archive
exit 0
# rm current schedule, after backing it up
;;
cat|c)
shift
cat "$TODAY_FILE"
exit 0
;;
help|h|-h|--help)
shift
cat << EOF
qc -- bash wrapper for quart
Usage:
$0 [OPTION]
$0 - [quart option]
OPTIONS:
init | i initialize quart home
new | n create new schedule (archives current one)
remove | rm remove current schedule (and archive it)
edit | e edit current schedule
cat | c print current schedule
help | h show this help
- pass arguments to quart
EOF
exit 0
;;
*)
echo "qc: '$1' is not a valid option"
shift
exit 1
;;
esac
|