/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-08-01 19:54:49 UTC
  • Revision ID: tim@ed.am-20120801195449-fcyrejq9aazxa5l5
detect extra arguments and extend --help message

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,
42
44
    "  -a, --all              display all sections\n".
43
45
    "  -e, --edit             edit your todo file\n".
44
46
    "  -h, --headers          show setion headers\n".
 
47
        "  -l, --list             show the list in your pager (see notes)\n".
45
48
    "  -s, --section=SECTION  display sections matching the regular expression\n".
46
49
    "      --help     display this help and exit\n".
47
50
    "      --version  output version information and exit\n".
49
52
        "Running without any options is the same as running with --section=TODO and\n".
50
53
        "lists the default section of the todo file.\n".
51
54
        "\n".
52
 
        "The environment variables EDITOR is used.\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".
 
58
        "\n".
 
59
        "The environment variables EDITOR and PAGER are used.\n".
53
60
        "\n".
54
61
        "Please report bugs to Tim Marston <tim\@ed.am>.\n";
55
62
    exit( 0 );
75
82
$todo_dir = glob( $todo_dir );
76
83
( -f $todo_dir ) and die "$todo_dir exists and is a file";
77
84
 
 
85
# less mode
 
86
if( $mode_less )
 
87
{
 
88
    ( ! -f "$todo_dir/todo" ) && die "no todo file";
 
89
        $mode_edit = 1;
 
90
}
 
91
 
78
92
# edit mode
79
93
if( $mode_edit )
80
94
{
111
125
 
112
126
    # determine editor from environment, default to "emacs -nw"
113
127
        my $editor;
114
 
        $editor = $ENV{ 'EDITOR' };
115
 
        defined $editor or $editor = 'emacs -nw';
 
128
        if( $mode_less ) {
 
129
                $editor = $ENV{ 'PAGER' };
 
130
                defined $editor or $editor = 'less';
 
131
        }
 
132
        else {
 
133
                $editor = $ENV{ 'EDITOR' };
 
134
                defined $editor or $editor = 'emacs -nw';
 
135
        }
116
136
    my @exec_array = split( / +/, $editor );
117
137
    push( @exec_array, "$todo_dir/todo" );
118
138