diff --git a/todo b/todo index a9176ea..668dd8b 100644 --- a/todo +++ b/todo @@ -10,12 +10,14 @@ use Getopt::Long; sub readtodo(); my $file = "$ENV{HOME}/todo.txt"; -my ($delete, $help); +my ($delete, $help, $edit); Getopt::Long::GetOptions( "del" => \$delete, "d" => \$delete, "delete" => \$delete, +"edit" => \$edit, +"e" => \$edit, "help" => \$help ); @@ -25,8 +27,14 @@ if ($help) { say " $0 --d NUM"; say " deletes string number NUM"; say ""; + say " $0 --edit"; + say " $0 --e"; + say " edit todo file with default editor"; + say ""; say " $0 some thing to-do"; say " adds memo"; + say ""; + say "N.B. because weirdnes of Getopt module, you ca use -- or - as option prefix"; exit 0; } @@ -48,6 +56,52 @@ if ($delete) { } close TD; +} elsif ($edit) { + my $editor; + + if (defined($ENV{editor})) { $editor = $ENV{editor}; } + elsif (defined($ENV{EDITOR})) { $editor = $ENV{EDITOR}; } + +# i hope you do not use debian and your $editor is unset :) + unless (defined($editor)) { + if (-f '/usr/bin/vim') { + $editor = '/usr/bin/vim'; # the most orthodox editor :) my favourite + } elsif (-f '/usr/bin/nvim') { + $editor = '/usr/bin/nvim'; + } elsif (-f '/usr/bin/neovim') { + $editor = '/usr/bin/neovim'; # duh, one more name for neovim + } elsif (-f '/usr/bin/nano') { + $editor = '/usr/bin/nano'; # seriously? + } elsif (-f '/usr/bin/micro') { + $editor = '/usr/bin/micro'; # oh, c'mon + } elsif (-f '/usr/bin/emacs') { + $editor = '/usr/bin/emacs'; # really? + } elsif (-f '/usr/bin/vi') { + $editor = '/usr/bin/vi'; # do you really use it? + } elsif (-f '/usr/bin/motor') { + $editor = '/usr/bin/motor'; # where did you found it? + } elsif (-f '/usr/bin/mcedit') { + $editor = '/usr/bin/mcedit'; # yup + } elsif (-f '/usr/bin/pico') { + $editor = '/usr/bin/pico'; # oh, yea? + } elsif (-f '/usr/bin/zile') { + $editor = '/usr/bin/zile'; # hmm + } elsif (-f '/usr/bin/joe') { + $editor = '/usr/bin/joe'; # hope you set it up correctly :) + } elsif (-f '/usr/bin/mle') { + $editor = '/usr/bin/mle'; # as my collegue says - fucking lua, he really don't like lua, beacuse he knows it + } elsif (-f '/usr/bin/slap') { + $editor = '/usr/bin/slap'; # editor in js? you must be kidding! + } elsif (-f '/usr/bin/jed') { + $editor = '/usr/bin/jed'; # yup + } else { + say "Either you have no acceptable editor in your system or something went wrong."; +# i couldn't find any suitable editor, you're fucking kidding? how d' you work? + exit 1; + } + } + + exec ($editor, $file); } else { my @TODO = readtodo();