-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject
executable file
·203 lines (181 loc) · 3.49 KB
/
project
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
# Copyright (C) 2009-2017 Serge Hallyn <[email protected]>
GTDDIR=~/gtd
CONFIGDIR=~/.config
# User might specify different GTD dir
[ -f "${CONFIGDIR}/gtd/config" ] && . "${CONFIGDIR}/gtd/config"
gtd=${GTDDIR}
VIM=vim
type gvim > /dev/null 2>&1 && VIM=gvim
if [ ! -d $gtd/Projects ]; then
echo "Please mount gtd"
exit 1
fi
delete_project()
{
local p="$1"
if [ ! -e "$gtd/Projects/$p" ]; then
echo "No such project: $p"
exit 1
fi
read -p "Are you sure you want to delete $p?" y
if [ "$y" = "y" -o $y = "yes" ]; then
rm -rf "$gtd/Projects/$p"
exit 0;
fi
echo "Not deleting"
}
new_proj()
{
local p="$1"
if [ -e "$gtd/Projects/$p" ]; then
echo "Project $p already exists"
exit 1
fi
mkdir -p "$gtd/Projects/$p"
}
cat_proj()
{
local p="$1"
local d="$gtd/Projects/$p"
if [ -f "$d" ]; then
cat "$d"
return
fi
if [ ! -d "$d" ]; then
echo "Project $p does not exist"
exit 1
fi
for f in "$d/summary.otl" "$d/log.otl" "$d/actions.otl"; do
if [ -f $f ]; then
echo ">>>> $f <<<<"
cat $f
fi
done
}
edit_proj()
{
local p="$1"
local d="$gtd/Projects/$p"
if [ -f "$d" ]; then
if [ "$EDITOR" = "edbrowse" ]; then
edbrowse "$d"
else
$VIM "$d"
fi
return
fi
if [ ! -d "$d" ]; then
echo "Project $p does not exist"
exit 1
fi
if [ "$EDITOR" = "edbrowse" ]; then
edbrowse "$d"
else
$VIM -o "$d/summary.otl" "$d/log.otl" "$d/actions.otl"
fi
}
start_proj()
{
local p="$1"
new_proj $p
edit_proj $p
}
if uname | grep -q "Darwin"; then
darwin=1
else
darwin=0
fi
list_projects()
{
printf "%-40s" "Project"
echo "| Last updated"
for p in $gtd/Projects/*; do
q=`basename $p`
printf "%-40s| " "$q"
if [ "$darwin" = "1" ]; then
stat -f "%m%t%Sm" "$p" | cut -f2-
else
stat -c %y "$p"
fi
done
}
complete_proj()
{
local p="$1"
y=`date +%Y`
d="$gtd/Completed/$y"
mkdir -p $d
newp="$d/$p"
if [ -d "$d/$p" ]; then
i=1;
while [ -d "$d/$p.$i" ]; do
i=$((i+1))
done
echo "A completed $p already exists, therefore I am"
echo "using $p.$i as the project name."
newp="$d/$p.$i"
fi
mv "$gtd/Projects/$p" "$newp"
}
postpone_proj()
{
local p="$1"
if [ -d "$gtd/Postponed/$p" ]; then
echo "A postponed project named $p already exists"
exit 1
fi
mv "$gtd/Projects/$p" "$gtd/Postponed/$p"
}
list_actions()
{
echo "not yet implemented"
}
usage()
{
local me=`basename $1`
echo "Usage:"
echo " $me [l|list]: list projects"
echo " $me [[e|edit] PROJ]: edit details of PROJ"
echo " $me [[n|new] PROJ]: create new project called PROJ"
echo " $me [[s|start] PROJ]: create new project called PROJ and edit"
echo " $me [[c|complete] PROJ]: move project PROJ to this year's completed list"
echo " $me [[d|delete] PROJ]: delete project PROJ"
echo " $me [[p|postpone] PROJ]: move project to postponed list"
echo " $me [[a|actions] PROJ]: list actions for project PROJ"
}
if [ $# -eq 0 ]; then
usage $0
exit 1
fi
if [ $1 = "l" -o $1 = "list" ]; then
list_projects
exit 0
elif [ $1 = "e" -o $1 = "edit" ]; then
edit_proj $2
exit 0
elif [ $1 = "cat" ]; then
cat_proj $2
exit 0
elif [ $1 = "n" -o $1 = "new" ]; then
new_proj $2
exit 0
elif [ $1 = "s" -o $1 = "start" ]; then
start_proj $2
exit 0
elif [ $1 = "c" -o $1 = "complete" ]; then
complete_proj $2
exit 0
elif [ $1 = "p" -o $1 = "postpone" ]; then
postpone_proj $2
exit 0
elif [ $1 = "h" -o $1 = "help" ]; then
usage $0
exit 0
elif [ $1 = "a" -o $1 = "actions" ]; then
list_actions $2
exit 0
elif [ $1 = "d" -o $1 = "delete" ]; then
delete_project $2
exit 0
fi