Add todo - simple TODO manager
This commit is contained in:
82
todo
Normal file
82
todo
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings "all";
|
||||
use 5.10.0;
|
||||
use Getopt::Long;
|
||||
|
||||
sub readtodo();
|
||||
|
||||
my $file = "$ENV{HOME}/todo.txt";
|
||||
my ($delete, $help);
|
||||
|
||||
Getopt::Long::GetOptions(
|
||||
"del" => \$delete,
|
||||
"d" => \$delete,
|
||||
"delete" => \$delete,
|
||||
"help" => \$help
|
||||
);
|
||||
|
||||
if ($help) {
|
||||
say "Usage: $0 --delete NUM";
|
||||
say " $0 --del NUM";
|
||||
say " $0 --d NUM";
|
||||
say " deletes string number NUM";
|
||||
say "";
|
||||
say " $0 some thing to-do";
|
||||
say " adds memo";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($delete) {
|
||||
say Dumper(\@ARGV);
|
||||
die "NUM not set\n" if ($ARGV[0] !~ /^\d+$/);
|
||||
my @TODO = readtodo();
|
||||
die "NUM too big\n" if ($ARGV[0] > @TODO);
|
||||
|
||||
my $cnt = 0;
|
||||
my $str = '';
|
||||
open (TD, ">", $file) or die "Unable to open $file: $!\n";
|
||||
|
||||
for (my $i = 0; $i < @TODO; $i++) {
|
||||
next if ($i == $ARGV[0]);
|
||||
next unless (defined($TODO[$i]));
|
||||
print sprintf("%s. %s\n", $cnt, $TODO[$i]);
|
||||
print TD sprintf("%s. %s\n", $cnt, $TODO[$i]);
|
||||
$cnt++;
|
||||
}
|
||||
|
||||
close TD;
|
||||
} else {
|
||||
die "Specify what to put in memo\n" unless (@ARGV > 0);
|
||||
|
||||
my @TODO = readtodo();
|
||||
push @TODO, join(" ", @ARGV);
|
||||
|
||||
open (TD, ">", $file) or die "Unable to open $file: $!\n";
|
||||
|
||||
for (my $i = 0; $i < @TODO; $i++) {
|
||||
next unless (defined($TODO[$i]));
|
||||
print sprintf("%s. %s\n", $i, $TODO[$i]);
|
||||
print TD sprintf("%s. %s\n", $i, $TODO[$i]);
|
||||
}
|
||||
|
||||
close TD;
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
||||
sub readtodo() {
|
||||
my @TODO;
|
||||
open (T, "<", $file) or return @TODO;
|
||||
@TODO = <T>;
|
||||
close T;
|
||||
|
||||
@TODO = map {
|
||||
chomp;
|
||||
$_ =~ /\s*\d+\. (.+)/;
|
||||
$1;
|
||||
} @TODO;
|
||||
|
||||
return @TODO;
|
||||
}
|
||||
Reference in New Issue
Block a user