taskwiki
taskwiki copied to clipboard
Suggestion for linking tasks to a vimwiki page
Wish I were better at vimscript so I could do more than throw peanuts from the peanut gallery. But it would be great if a task could link to a vimwiki page dedicated to the task for notes and discussion around the task. You could use the task id for the name of the page. I know you can annotate a note with the name of the file the task is on but that isn't much help.
I came here to create an issue in a similar vein. Although what I was going to suggest was a command that would essential grep the vimwiki's looking for the id for the task under the cursor. Doing that would allow me to jump to the note, get context, and maybe complete it. Afterwards I would jump back to potentially the viewport that contained it and refresh to see the new state.
I have created #270 that does exactly this.
I've been using https://github.com/mikebobroski/tasknote/blob/master/tasknote for associating a text file of notes for a given task.... and dreaming of the day when I'd have a vim keybinding to jump from the taskwiki task item to the text file for that task. I'm very excited to check out @nkakouros's #270 :)
@ahillio it ended up being a very easy function to write in vimscript. Here is how I did it https://github.com/skbolton/titan/blob/683db8d88b13bc9d8bfe010a13017798650824ac/nvim/nvim/plugin/wiki.vim#L37
Oh sweet! Do you know how to get the full task id from a vimscript function like that? My tasknote files are named like a2f23ef6-b63a-4c35-9389-afe8b80d9291.mkd and I'm only able to get a2f23ef6 from this so far. Your vimfunction is at least a great start for me :)
Currently my attempt looks like:
function TaskSearch()
let line = getline('.')
let task_id = split(line, "#")[1]
let task_note = execute('grep -r task_id ~/.task/notes/')
execute('edit ~/.task/notes/$task_note')
endfunction
command! TaskSearch :call TaskSearch()
nnoremap <leader>tn :TaskSearch <Enter>
and obviously the $task_note results in a "bad filename" error, but it illustrates what I'm trying to achieve.
In the case of using tasknote script to associate a ~/.task/notes/ad04e482-5ec2-4c34-a03f-b39344b99ef4.mkd text file with the task of uuid ad04e482-5ec2-4c34-a03f-b39344b99ef4, the following vimscript will allow you to open that file from your vimwiki task list.
function TaskSearch()
let line = getline('.')
let task_id = split(line, "#")[1]
let task_note = system('task ' . task_id . ' information | grep UUID | sed "s/UUID //" | tr -d "\n"')
exe printf("e ~/.task/notes/%s.mkd", task_note)
endfunction
command! TaskSearch :call TaskSearch()
nnoremap <leader>tn :TaskSearch <Enter>
If the file doesn't exist it will be created. In which case this function is a little incomplete as it should then add a [tasknote] annotation to the task.
@ahillio if you want the full uuid I would do this.
let task_note = system('task _get "' . task_id . '".uuid')
for example this is how you can get a task uuid in taskwarrior
task _get "7c71b13d".uuid
7c71b13d-bee0-491e-9377-b0409f701341
thanks @skbolton, that's cleaner :)
This should also work and could be more robust as it uses taskwiki/tasklib to get the uuid:
let task_id = py3eval("SelectedTasks().tasks[0].task['uuid']")
this is exactly what I needed! I've rewritten it to look like this:
"adding notes to tasks:
"TODO: should automatically make the notes directory
function TaskSearch()
let task_id = py3eval("SelectedTasks().tasks[0].task['uuid']")
exe printf("e ~/.task/notes/%s.md", task_id)
endfunction
command! TaskSearch :call TaskSearch()
nnoremap <leader>tn :TaskSearch <Enter>
someday #270 will be finished and be a more legitimate version of this :)