jschlatow / taskopen

Tool for taking notes and open urls with taskwarrior
GNU General Public License v2.0
364 stars 31 forks source link

Allow for arbitrary custom commands #91

Closed scottkosty closed 8 years ago

scottkosty commented 8 years ago

Currently taskopen only allows for two custom commands. Allowing for more custom commands would make taskopen more flexible.

Here is an idea for the design of the implementation:

Loop through the keys in the %config hash and find keys that match the following regex:

CUSTOM\d+_REGEX

Then create another hash called %custom_regexes where as the key you store the regex and as the value the command.

Then in your create_cmd() instead of

elsif ($CUSTOM1_REGEX && $file =~ m/^$CUSTOM1_REGEX/) {
    $cmd = qq{$CUSTOM1_CMD};
}
elsif ($CUSTOM2_REGEX && $file =~ m/^$CUSTOM2_REGEX/) {
    $cmd = qq{$CUSTOM2_CMD};
}

there would be a loop through the keys of %custom_regexes testing each key (regex) against the $file string. The loop would stop on the first match (it should be documented whether it is the numbers of CUSTOMN_REGEX that determine priority or the order that they are given in the config file) and use the value of %custom_regexes for the key that matched, which is the command.