Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 58 lines (48 sloc) 1.086 kB
#!/usr/bin/env perl6
use Term::ANSIColor;
my @tasks;
my $yay = colored('', 'green');
my $nay = colored('', 'red');
INIT {
@tasks = lines(slurp('tasks')).map: {
next if $_ eq '';
$_.substr(1) => ($_.substr(0, 1) eq '+')
}
}
#= add a new TODO item
multi MAIN(*@words) {
@tasks.push: @words.join(' ') => 0;
}
#= remove an item at the desired index
multi MAIN('rm', Int $which) {
@tasks.splice($which, 1);
}
#= list [--all] items (only the incomplete ones by default)
multi MAIN('ls', Bool :$all) {
for @tasks.kv -> $i, $t {
if $all or !$t.value {
say "#$i {$t.value ?? $yay !! $nay} {$t.key}"
}
}
}
#= mark an item as done
multi MAIN('check', Int $which) {
@tasks[$which].value = 1
}
#= mark an item as undone
multi MAIN('undo', Int $which) {
@tasks[$which].value = 0
}
#= clear the list
multi MAIN('clear') {
@tasks = ();
}
END {
my $repr = @tasks.map({
($_.value ?? '+' !! '-') ~ $_.key
}).join("\n");
given open 'tasks', :w {
.say($repr);
.close;
}
}
Jump to Line
Something went wrong with that request. Please try again.