-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathrawedit
executable file
·70 lines (54 loc) · 1.51 KB
/
rawedit
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
#!/usr/bin/perl -w -CLASo
# Edit the raw annotation text.
# Usage: rawedit <id|uuid> "annotation text"
# Use with the following lines in taskopen's config file:
# [Actions]
# edit.regex = ".*"
# edit.command = "rawedit $UUID \"$ANNOTATION\""
#
# [CLI]
# alias.edit = "normal --include=edit"
use File::Temp;
if ($#ARGV != 1) {
print("Usage: rawedit <id|uuid> \"annotation text\"");
exit 1
}
my $EDITOR = $ENV{"EDITOR"};
my $id = $ARGV[0];
my $text = $ARGV[1];
my $new = raw_edit($text);
modify_annotation($id, $text, $new);
sub raw_edit {
my $old = $_[0];
my $filename = File::Temp::tmpnam();
open(my $fh, '>', $filename) or die "can't open $filename: $!";
print($fh $old);
close($fh);
system(qq/$EDITOR "$filename"/);
open($fh, '<', $filename) or die "can't open $filename: $!'";
my @lines = <$fh>;
close($fh);
unlink($filename);
# taskwarrior does not support multi-line annotations
# TODO fix if #1172 has been solved
my $result = $lines[0];
chomp($result);
return $result;
}
sub modify_annotation {
my $id = $_[0];
my $old = $_[1];
my $new = $_[2];
if ($old ne $new) {
# TODO remove as soon as tw bug TW-1821 has been fixed ('/'s must still be escaped)
if ($old =~ m/\// || $new =~ m/\//) {
print("Cannot replace annotations which contain '/'s (see #1174).");
exit 1
}
# END REMOVE
`task $id mod /$old/$new/ > /dev/null`;
}
else {
print("No changes detected");
}
}