40
36
print "todo - display your todo file\n\n".
41
#01234567890123456789012345678901234567890123456789012345678901234567890123456789
42
"Usage: $app_name [OPTIONS]\n\n".
44
" -a, --all display all sections\n".
45
" -e, --edit edit your todo file\n".
46
" -h, --headers show setion headers\n".
47
" -l, --list show the list in your pager (see notes)\n".
48
" -s, --section=SECTION display sections matching the regular expression\n".
49
" --help display this help and exit\n".
50
" --version output version information and exit\n".
52
"Running without any options is the same as running with --section=TODO and\n".
53
"lists the default section of the todo file.\n".
55
"The advantage of using '--list' is that the pager is run as if the\n".
56
"todo list were being edited. This means that if you decide to spawn an\n".
57
"editor from you pager and edit the list, these changes get noticed.\n".
59
"The environment variables EDITOR and PAGER are used.\n".
61
"Please report bugs to Tim Marston <tim\@ed.am>.\n";
37
"Usage: $app_name [OPTIONS]\n\n".
39
" -a, --all display all sections\n".
40
" -e, --edit edit your todo file\n".
41
" -h, --headers show setion headers\n".
42
" -s, --section=SECTION display this named section\n".
43
" --help display this help and exit\n".
44
" --version output version information and exit\n";
66
49
if( $mode_version ) {
68
"Copyright (C) 2011, 2012 Tim Marston.\n".
69
"http://ed.am/software/todo\n";
51
"Copyright (C) 2011 Tim Marston.\n";
82
64
$todo_dir = glob( $todo_dir );
83
65
( -f $todo_dir ) and die "$todo_dir exists and is a file";
88
( ! -f "$todo_dir/todo" ) && die "no todo file";
95
70
# create the todo directory, as necessary
96
if( ! -d $todo_dir ) {
97
mkdir $todo_dir or die "couldn't create todo directory";
98
`bzr init --no-aliases -q "$todo_dir"`;
99
$? == 0 or die "couldn't init bzr repo";
102
# create a default todo file, as necessary
103
if( ! -f "$todo_dir/todo" ) {
104
open FILE, ">$todo_dir/todo" or die "couldn't create default todo file";
105
my $content = <<"EOT";
106
<!-- This file uses Markdown syntax. For more info about Markdown
107
syntax, see http://daringfireball.net/projects/markdown/syntax.
109
There should be a main H1 header called "TODO" for the main todo
110
list section (one has been added for you below). You can also add
111
as many more sections as you like for other lists. And feel free
112
to delete this comment! -->
117
* make a list of things to do
120
print FILE $content or die "couldn't write default todo file";
122
`bzr add --no-aliases -q "$todo_dir/todo"`;
123
$? == 0 or die "couldn't add todo file to bzr repo";
71
if( ! -d $todo_dir ) {
72
mkdir $todo_dir or die "couldn't create todo directory";
73
`bzr init --no-aliases -q "$todo_dir"`;
74
$? == 0 or die "couldn't init bzr repo";
76
$? == 0 or die "couldn't create initial todo file";
77
`bzr add --no-aliases -q "$todo_dir/todo"`;
78
$? == 0 or die "couldn't add todo file to bzr repo";
126
81
# determine editor from environment, default to "emacs -nw"
129
$editor = $ENV{ 'PAGER' };
130
defined $editor or $editor = 'less';
133
$editor = $ENV{ 'EDITOR' };
134
defined $editor or $editor = 'emacs -nw';
82
my $editor = $ENV{ 'EDITOR' };
83
defined $editor or $editor = 'emacs -nw';
136
84
my @exec_array = split( / +/, $editor );
137
85
push( @exec_array, "$todo_dir/todo" );
139
# detect emacs and try to use markdown-mode
140
$exec_array[ 0 ] eq "emacs" and
141
push( @exec_array, '--funcall=markdown-mode' );
87
# detect emacs and try to use markdown-mode
88
$exec_array[ 0 ] eq "emacs" and push( @exec_array, '--funcall=markdown-mode' );
144
91
system( @exec_array );
146
die "can't start editor, check EDITOR envionment variable";
148
# check for changes and commit it
149
$output = `bzr status --no-aliases "$todo_dir/todo"`;
150
$? == 0 or die "couldn't check bzr rerpo status";
152
if( $output ne "" ) {
153
`bzr commit --no-aliases -q -m - "$todo_dir/todo"`;
154
$? == 0 or die "couldn't commit to bzr repo";
157
# after editing, exit
161
# function to display a line
164
my ( $line, $section ) = @_;
165
state $old_section = '';
167
# detect section change
168
if( $section ne $old_section ) {
169
$old_section = $section;
171
# display section heading
172
if( $display_headers || $display_all ) {
174
( "=" x length( $section ) )."\n";
92
$? == 0 or die "unable to exec editor";
94
# check for changes and commit it
95
$output = `bzr status --no-aliases "$todo_dir/todo"`;
96
$? == 0 or die "couldn't check bzr rerpo status";
99
`bzr commit --no-aliases -q -m - "$todo_dir/todo"`;
100
$? == 0 or die "couldn't commit to bzr repo";
178
# replace tabs with 4 spaces
186
107
# scan through file
187
my $candidate_section = '';
108
my $next_section = '';
188
109
my $section = '';
110
my $old_section = '';
190
111
open FILE, "<$todo_dir/todo" or die "can't open todo file";
193
115
# detect the line after section headings, and thus sections
194
if( /^[-=]{2,}/ && $candidate_section ne '' ) {
195
$section = $candidate_section;
196
$candidate_section = '';
116
if( /^[-=]{2,}/ && $next_section ne '' ) {
117
$section = $next_section;
201
120
# detect section headings
202
if( /^[-_\.A-Za-z0-9 ]+$/ ) {
203
$candidate_section = $_;
204
chomp $candidate_section;
121
elsif( /^[A-Z]+$/ ) {
123
chomp( $next_section );
125
# we have neither a section heading nor the line after
207
$candidate_section = '';
211
display_line( $last_line, $section ) if( $last_line ne '' );
214
if( ( lc( $section ) eq lc( $display_section ) ) ||
215
( $section && $display_all ) )
130
if( $section eq $display_section ||
133
# detect section change
134
if( $section ne $old_section ) {
135
$old_section = $section;
137
# display section heading
138
if( $display_headers ||
141
my $heading = 'TODO';
142
$heading .= ' ('.lc( $section ).')' if $section ne "IMMEDIATE";
144
( "=" x length( $heading ) )."\n";
148
# replace tabs with 4 spaces
223
display_line( $last_line, $section ) if( $last_line ne '' );