jschlatow / taskopen

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

Question on how to use custom actions #149

Closed leandrochiarini closed 2 years ago

leandrochiarini commented 2 years ago

Sorry, I feel like this a very silly question but I am struggling with the new custom actions, I just want to set .md files to be opened with nvim.

[General]
taskbin=task
taskargs
no_annotation_hook="addnote $ID"
task_attributes="priority,project,tags,description"
--sort:"urgency-,annot"
--active-tasks:"+PENDING"
path_ext=/usr/share/taskopen/scripts

[Actions]
notes.regex = "(N|n)otes?"
notes.command = "$EDITOR $HOME/tasknotes/$UUID.txt"
markdown.target = annotations
markdown.regex = ".*md"
markdown.labelregex = ".*"
markdown.command = "nvim $FILE"
markdown.modes = normal,any,batch
markdown.filtercommand = ""
markdown.inlinecommand = ""

The notes action is working fine, but anything else is being picked up as files: for instance, the result of a taskopen 36 --debug on a file with many annotations is

 1) files: /home/lchiarini/Desktop/2022-06-20-Note-17-50.xopp
    ("Example") -- 36
 2) files: /home/lchiarini/Desktop/test.md
    ("Example") -- 36
 3) notes: note
    ("Example") -- 36

I don't understand why the second one is being taken as files rather than markdown. Did I misunderstand the way of declaring new custom actions?

jschlatow commented 2 years ago

@leandrochiarini, can you please post the output of taskopen diagnostics?

leandrochiarini commented 2 years ago

Of course, sorry

Environment
  Platform:       Linux
  Taskopen:       fatal: No names found, cannot describe anything.
  Taskwarrior:    2.6.1 (c564bbc0b)
  Configuration:  /home/lchiarini/.taskopenrc
Current configuration
  Binaries and paths:
    taskbin            = task
    taskargs           =
    editor             = /usr/bin/nvim
    path_ext           = /usr/share/taskopen/scripts
  General:
    debug              = false
    no_annotation_hook = addnote $ID
    task_attributes    = priority,project,tags,description
  Action groups:
  Subcommands:
    default            = normal
  Actions:
    files
      .target          = annotations
      .regex           = ^[\.\/~]+.*\.(.*)
      .labelregex      = .*
      .command         = xdg-open $FILE
      .modes           = batch,any,normal
    notes
      .target          = annotations
      .regex           = (N|n)otes?
      .labelregex      = .*
      .command         = $EDITOR $HOME/tasknotes/$UUID.txt
      .modes           = batch,any,normal
jschlatow commented 2 years ago

I don't see a 'markdown' action in your diagnostics. Can you double check that you put into the correct config file? According to your diagnostics, this would be ~/.taskopenrc.

leandrochiarini commented 2 years ago

I had previously installed via the arch linux repository (which fixed the fatal error on the version of taskopen), installing again according the instructions in the repository (and fixing the link to the .taskopenrc as you mentioned), which now gives

Environment
  Platform:       Linux
  Taskopen:       v2.0.0beta
  Taskwarrior:    2.6.1 (c564bbc0b)
  Configuration:  /home/lchiarini/.taskopenrc
Current configuration
  Binaries and paths:
    taskbin            = task
    taskargs           =
    editor             = /usr/bin/nvim
    path_ext           = /usr/share/taskopen/scripts
  General:
    debug              = false
    no_annotation_hook = addnote $ID
    task_attributes    = priority,project,tags,description
  Action groups:
  Subcommands:
    default            = normal
  Actions:
    files
      .target          = annotations
      .regex           = ^[\.\/~]+.*\.(.*)
      .labelregex      = .*
      .command         = xdg-open $FILE
      .modes           = batch,any,normal
    notes
      .target          = annotations
      .regex           = (N|n)otes?
      .labelregex      = .*
      .command         = $EDITOR $HOME/tasknotes/$UUID.txt
      .modes           = batch,any,normal
    markdown
      .target          = annotations
      .regex           = .*md
      .labelregex      = .*
      .command         = nvim $FILE
      .modes           = any

I did also just notice I get the error Invalid config option in [Actions]: , any: Invalid config option in [Actions]: , batch: so I changed markdown.modes to just any. Using taskopen 36 --debug again, I get:

Executing: task rc.verbose=blank,label,edit rc.json.array=on  context show
Executing: task rc.verbose=blank,label,edit rc.json.array=on   36 +PENDING export
Please select one or multiple actions:
 1) files: /home/lchiarini/Desktop/2022-06-20-Note-17-50.xopp
    ("Example") -- 36
    command: xdg-open $FILE
 2) files: /home/lchiarini/Desktop/test.md
    ("Example") -- 36
    command: xdg-open $FILE
 3) notes: note
    ("Example") -- 36
    command: $EDITOR $HOME/tasknotes/$UUID.txt

Thanks again for the quick reply.

jschlatow commented 2 years ago

By setting the modes to "any" you exclude the markdown action because the default mode is "normal". You can just omit markdown.modes to take the defaults.

In normal mode, the first matching action is displayed. Since the file action also matches and occurs first in the config file, it shadows the markdown action. You can change the order in the config file so that the markdown actions takes precedence.

leandrochiarini commented 2 years ago

Perfect! It works like a charm, thank you again for the help!