Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for linking tasks to a vimwiki page #217

Open
sdondley opened this issue Apr 30, 2019 · 11 comments
Open

Suggestion for linking tasks to a vimwiki page #217

sdondley opened this issue Apr 30, 2019 · 11 comments

Comments

@sdondley
Copy link

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.

@skbolton
Copy link

skbolton commented Dec 7, 2019

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.

@nkakouros
Copy link
Contributor

I have created #270 that does exactly this.

@ahillio
Copy link

ahillio commented Aug 25, 2020

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 :)

@skbolton
Copy link

skbolton commented Aug 26, 2020

@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

@ahillio
Copy link

ahillio commented Aug 26, 2020

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 :)

@ahillio
Copy link

ahillio commented Aug 26, 2020

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.

@ahillio
Copy link

ahillio commented Aug 26, 2020

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.

@skbolton
Copy link

@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

@ahillio
Copy link

ahillio commented Aug 26, 2020

thanks @skbolton, that's cleaner :)

@liskin
Copy link
Collaborator

liskin commented Aug 26, 2020

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']")

@Mastermjr
Copy link

Mastermjr commented Jun 28, 2023

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants