23
26
'a|all' => \$display_all,
24
27
'e|edit' => \$mode_edit,
25
28
'h|headers' => \$display_headers,
26
'section=s' => \$display_section,
29
'l|list' => \$mode_less,
30
's|section=s' => \$display_section,
27
31
'help' => \$mode_help,
28
32
'version' => \$mode_version,
30
34
print "Try `$app_name --help' for more information.\n";
36
40
print "todo - display your todo file\n\n".
41
#01234567890123456789012345678901234567890123456789012345678901234567890123456789
37
42
"Usage: $app_name [OPTIONS]\n\n".
39
44
" -a, --all display all sections\n".
40
45
" -e, --edit edit your todo file\n".
41
46
" -h, --headers show setion headers\n".
42
" -s, --section=SECTION display this named section\n".
47
" -l, --list show the list in your pager (see notes)\n".
48
" -s, --section=SECTION display sections matching the regular expression\n".
43
49
" --help display this help and exit\n".
44
" --version output version information 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";
49
66
if( $mode_version ) {
50
67
print "todo 1.0\n".
51
"Copyright (C) 2011 Tim Marston.\n".
68
"Copyright (C) 2011, 2012 Tim Marston.\n".
52
69
"http://ed.am/software/todo\n";
102
126
# determine editor from environment, default to "emacs -nw"
103
my $editor = $ENV{ 'EDITOR' };
104
defined $editor or $editor = 'emacs -nw';
129
$editor = $ENV{ 'PAGER' };
130
defined $editor or $editor = 'less';
133
$editor = $ENV{ 'EDITOR' };
134
defined $editor or $editor = 'emacs -nw';
105
136
my @exec_array = split( / +/, $editor );
106
137
push( @exec_array, "$todo_dir/todo" );
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";
178
# replace tabs with 4 spaces
130
186
# scan through file
131
my $next_section = '';
187
my $candidate_section = '';
132
188
my $section = '';
133
my $old_section = '';
134
190
open FILE, "<$todo_dir/todo" or die "can't open todo file";
138
193
# detect the line after section headings, and thus sections
139
if( /^[-=]{2,}/ && $next_section ne '' ) {
140
$section = $next_section;
194
if( /^[-=]{2,}/ && $candidate_section ne '' ) {
195
$section = $candidate_section;
196
$candidate_section = '';
143
201
# detect section headings
144
elsif( /^[-_\.A-Za-z0-9 ]+$/ ) {
146
chomp( $next_section );
148
# we have neither a section heading nor the line after
202
if( /^[-_\.A-Za-z0-9 ]+$/ ) {
203
$candidate_section = $_;
204
chomp $candidate_section;
153
if( ( $section eq $display_section ) ||
154
( $section && $display_all ) )
156
# detect section change
157
if( $section ne $old_section ) {
158
$old_section = $section;
160
# display section heading
161
if( $display_headers ||
165
( "=" x length( $section ) )."\n";
169
# replace tabs with 4 spaces
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 ) )
223
display_line( $last_line, $section ) if( $last_line ne '' );