/todo

To get this branch, use:
bzr branch http://bzr.ed.am/todo

« back to all changes in this revision

Viewing changes to todo

  • Committer: edam
  • Date: 2012-03-12 14:07:28 UTC
  • Revision ID: tim@ed.am-20120312140728-nv11dg8zapxs9gtj
added --list

Show diffs side-by-side

added added

removed removed

16
16
my $display_section = "TODO";
17
17
my $display_headers = 0;
18
18
my $mode_edit = 0;
 
19
my $mode_less = 0;
19
20
my $mode_help = 0;
20
21
my $mode_version = 0;
21
22
 
25
26
    'a|all' => \$display_all,
26
27
    'e|edit' => \$mode_edit,
27
28
    'h|headers' => \$display_headers,
 
29
        'l|list' => \$mode_less,
28
30
    's|section=s' => \$display_section,
29
31
    'help' => \$mode_help,
30
32
    'version' => \$mode_version,
31
 
) || @ARGV > 0 ) {
 
33
) ) {
32
34
    print "Try `$app_name --help' for more information.\n";
33
35
    exit( 1 );
34
36
}
36
38
# help mode
37
39
if( $mode_help ) {
38
40
    print "todo - display your todo file\n\n".
39
 
        #01234567890123456789012345678901234567890123456789012345678901234567890123456789
40
41
    "Usage: $app_name [OPTIONS]\n\n".
41
42
    "Options:\n".
42
43
    "  -a, --all              display all sections\n".
43
44
    "  -e, --edit             edit your todo file\n".
44
45
    "  -h, --headers          show setion headers\n".
45
 
    "  -s, --section=SECTION  display sections matching the regular expression\n".
 
46
        "  -l, --list             show the list in your pager (see notes)\n".
 
47
    "  -s, --section=SECTION  display this named section\n".
46
48
    "      --help     display this help and exit\n".
47
49
    "      --version  output version information and exit\n".
48
50
        "\n".
49
 
        "Running without any options is the same as running with --section=TODO and\n".
50
 
        "lists the default section of the todo file.\n".
 
51
        "The advantage of using '--list' is that the pager is run as if the\n".
 
52
        "todo list were being edited. This means that if you decide to spawn an\n".
 
53
        "editor from you pager and edit the list, these changes get noticed.\n".
51
54
        "\n".
52
 
        "The environment variables EDITOR is used.\n".
 
55
        "The environment variables EDITOR and PAGER are used.\n".
53
56
        "\n".
54
57
        "Please report bugs to Tim Marston <tim\@ed.am>.\n";
55
58
    exit( 0 );
75
78
$todo_dir = glob( $todo_dir );
76
79
( -f $todo_dir ) and die "$todo_dir exists and is a file";
77
80
 
 
81
# less mode
 
82
if( $mode_less )
 
83
{
 
84
    ( ! -f "$todo_dir/todo" ) && die "no todo file";
 
85
        $mode_edit = 1;
 
86
}
 
87
 
78
88
# edit mode
79
89
if( $mode_edit )
80
90
{
111
121
 
112
122
    # determine editor from environment, default to "emacs -nw"
113
123
        my $editor;
114
 
        $editor = $ENV{ 'EDITOR' };
115
 
        defined $editor or $editor = 'emacs -nw';
 
124
        if( $mode_less ) {
 
125
                $editor = $ENV{ 'PAGER' };
 
126
                defined $editor or $editor = 'less';
 
127
        }
 
128
        else {
 
129
                $editor = $ENV{ 'EDITOR' };
 
130
                defined $editor or $editor = 'emacs -nw';
 
131
        }
116
132
    my @exec_array = split( / +/, $editor );
117
133
    push( @exec_array, "$todo_dir/todo" );
118
134