-
Notifications
You must be signed in to change notification settings - Fork 5
/
sync-qtodo
executable file
·72 lines (64 loc) · 1.67 KB
/
sync-qtodo
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
#!/usr/bin/perl
use strict;
use warnings;
my $todoFile = "$ENV{HOME}/TODO";
my $notesFile = "$ENV{HOME}/NOTES";
my $remoteDir = "/home/user/to-do-o";
my $remoteFile = "$remoteDir/default.xml";
sub getTodos();
my $usage = "Usage:
$0
copy new qtodos into TODO, then generate qtodo from TODO
$0 --del
generate qtodo from TODO, overwriting qtodos
";
sub main(@){
my $del = shift if @_ == 1 and $_[0] eq '--del';
die $usage if @_ > 0;
system "n9u", "-s", "
mkdir -p $remoteDir
touch $remoteFile
";
my @todos = getTodos;
my %notes = map {chomp; $_ => 1} `cat $notesFile`;
@todos = grep {not defined $notes{$_}} @todos;
if(not defined $del and @todos > 0){
print "Adding qtodos to $todoFile\n";
system "todo-parse", "--add", @todos;
print "\n\n";
}
print "Replacing qtodo xml {backed up} from ${todoFile}'s git history\n";
my $xml = `todo-parse --notes --qtodo`;
my $tmpFile = "/tmp/qtodo_" . time();
open FH, "> $tmpFile" or die "Couldnt write $tmpFile\n";
print FH $xml;
close FH;
my $host = `n9`;
chomp $host;
system "scp", $tmpFile, "user\@$host:$remoteFile";
system "website-upload", "--skip-plotddr";
}
sub getTodos(){
my $xml = `n9 -s cat $remoteDir/default.xml`;
my $now = time();
system "n9", "-s", "
mkdir -p $remoteDir
chown user.users $remoteDir
file=\"$remoteFile\"
bak=\"${remoteFile}_bak_$now\"
mv \$file \$bak
";
my @todos;
while($xml =~ /<to-do\ (done="true")? [^>]* > ([^<]*) /gmx){
push @todos, $2;
}
for my $todo(@todos){
$todo = lc $todo;
$todo =~ s/\</</g;
$todo =~ s/\&/\&/g;
$todo =~ s/^\s*//;
$todo =~ s/\s*$//;
}
return @todos;
}
&main(@ARGV);