-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy patharchive
executable file
·39 lines (31 loc) · 873 Bytes
/
archive
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
#!/bin/bash
# This script is supposed to be used with an archive action such as the following:
# archfiles.regex = "/home/user/((?:Documents|Notes)/.*)"
# archfiles.command = "archive $FILE ~/archive/$LAST_MATCH"
# archfiles.filtercommand = "archive $FILE"
if [ $# -lt 1 ]; then
echo "Usage: $0 <srcpath> <dstpath>"
exit 1
fi
# only test if path is ready to be archived
SRCFILE=$1
# taskwarrior does not support search patterns with '/'s
# as a workaround, we replace the '/'s by a regex '.'
SEARCH=${SRCFILE//\//.}
if [ $# -eq 1 ]; then
res=$(task _ids ${SEARCH} | wc -l)
if [ $res -eq 1 ]; then
echo "okay"
exit 0
else
echo "Not archivable"
exit 1
fi
else
DSTFILE=$2
DSTPATH=$(dirname $2)
mkdir -p ${DSTPATH}
mv -i ${SRCFILE} ${DSTFILE}
ids=$(task uuids ${SEARCH})
task $ids denotate -- ${SRCFILE} && task $ids annotate -- ${DSTFILE}
fi