Last active
June 3, 2019 19:22
-
-
Save BTBTravis/d35b6993b2928a3e2aafb2b87b84d611 to your computer and use it in GitHub Desktop.
sort tasks vimwiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my @done_tasks; | |
my @todo_tasks; | |
my $todo_type = "todo"; | |
my $done_type = "done"; | |
my $last_task_type = "none"; | |
my $has_cacled_indent = 0; | |
my $indent = 0; | |
while (<>) { | |
if (not $has_cacled_indent) { | |
$indent = $_ =~ s/^(\s+).+/$1/rg; | |
$indent = length($indent); | |
$indent--; | |
$has_cacled_indent = 1; | |
} | |
if (/^\s{$indent}- \[X/) { | |
push @done_tasks, $_; | |
$last_task_type = $done_type; | |
} elsif (/^\s{$indent}- \[/) { | |
push @todo_tasks, $_; | |
$last_task_type = $todo_type; | |
} elsif ($last_task_type eq $todo_type && @todo_tasks > 0) { | |
$todo_tasks[@todo_tasks - 1] = $todo_tasks[@todo_tasks - 1] . $_; | |
} elsif ($last_task_type eq $done_type && @done_tasks > 0) { | |
$done_tasks[@done_tasks - 1] = $done_tasks[@done_tasks - 1] . $_; | |
} | |
} | |
foreach (@todo_tasks) { | |
print; | |
} | |
foreach (@done_tasks) { | |
print; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment