Skip to content

Commit c7a58cf

Browse files
committed
add :DisplayTaskID and :CopyTaskID commands
1 parent 6b3a789 commit c7a58cf

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

autoload/vimwiki_tasks.vim

+15
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,18 @@ function! vimwiki_tasks#verify_taskwarrior()
323323
throw "`task` not found or not executable"
324324
endif
325325
endfunction
326+
327+
function! vimwiki_tasks#display_task_id(copy_to_clipboard)
328+
let l:uuid = matchstr(getline(line('.')), '\v\* \[.\].*#\zs[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}')
329+
if l:uuid != ''
330+
let l:tw_task = vimwiki_tasks#load_task(l:uuid)
331+
let l:msg = "Task ID: ".l:tw_task.id
332+
if (a:copy_to_clipboard)
333+
let @+ = l:tw_task.id
334+
let l:msg .= ", copied to clipboard"
335+
endif
336+
echo l:msg
337+
else
338+
echo "Could not find a task on this line!"
339+
endif
340+
endfunction

ftplugin/vimwiki.vim

+3
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ if vimwiki_tasks#config('taskwarrior_integration', 1)
77

88
" sync the tasks from TW to vimwiki
99
call vimwiki_tasks#read()
10+
11+
command! DisplayTaskID call vimwiki_tasks#display_task_id(0)
12+
command! CopyTaskID call vimwiki_tasks#display_task_id(1)
1013
endif

0 commit comments

Comments
 (0)