Skip to content

Commit 6b3a789

Browse files
committed
configuration option to specify additional args for task
This can be useful for example to set an alternative .taskrc location to keep the vimwiki tasks in a separate file or for testing purposes to keep the main task files clean
1 parent bd9453c commit 6b3a789

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

autoload/vimwiki_tasks.vim

+16-12
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,24 @@ function! vimwiki_tasks#write()
1212
let l:task = vimwiki_tasks#parse_task(l:line, l:defaults)
1313
" add the task if it does not have a uuid
1414
if l:task.uuid == ""
15-
call <SID>System(l:task.task_cmd.' add '.shellescape(l:task.description).' '.<SID>JoinTags(l:task.tags_list).' '.l:task.task_meta)
15+
call <SID>Task(l:task.task_args.' add '.shellescape(l:task.description).' '.<SID>JoinTags(l:task.tags_list).' '.l:task.task_meta)
1616
" find the id and the uuid of the newly created task
17-
let l:id = substitute(<SID>System("task newest limit:1 rc.verbose=nothing rc.color=off rc.defaultwidth=999 rc.report.newest.columns=id rc.report.newest.labels=ID"), "\n", "", "")
18-
let l:uuid = substitute(<SID>System("task ".l:id." uuid"), "\n", "", "")
17+
let l:id = substitute(<SID>Task("newest limit:1 rc.verbose=nothing rc.color=off rc.defaultwidth=999 rc.report.newest.columns=id rc.report.newest.labels=ID"), "\n", "", "")
18+
let l:uuid = substitute(<SID>Task(l:id." uuid"), "\n", "", "")
1919
" add the uuid to the line and remove the #TW indicator
2020
call setline(l:i, <SID>RemoveTwIndicator(l:line)." #".l:uuid)
2121

2222
if vimwiki_tasks#config('annotate_origin', 0)
2323
" annotate the task to reference the vimwiki file
24-
let l:cmd = 'task '.l:id.' annotate vimwiki:'.expand('%:p')
25-
call <SID>System(l:cmd)
24+
call <SID>Task(l:id.' annotate vimwiki:'.expand('%:p'))
2625
endif
2726
" see if we need to update the task in TW
2827
else
2928
let l:tw_task = vimwiki_tasks#load_task(l:task.uuid)
3029
" don't update deleted tasks
3130
if l:tw_task.status !=# 'Deleted'
3231
if l:task.description !=# l:tw_task.description || l:task.due !=# l:tw_task.due || l:task.project !=# l:defaults.project || <SID>JoinTags(l:task.tags_list) !=# <SID>JoinTags(l:tw_task.tags_list)
33-
call <SID>System(l:task.task_cmd.' rc.confirmation=no uuid:'.l:task.uuid.
32+
call <SID>Task(l:task.task_args.' rc.confirmation=no uuid:'.l:task.uuid.
3433
\ ' modify '.shellescape(l:task.description).' '.
3534
\ <SID>JoinTags(l:task.tags_list).' '.<SID>TagsToRemove(l:tw_task.tags_list, l:task.tags_list).
3635
\ ' '.l:task.task_meta)
@@ -41,7 +40,7 @@ function! vimwiki_tasks#write()
4140
elseif match(l:line, '\v\* \[X\].*#[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}') != -1
4241
let l:task = vimwiki_tasks#parse_task(l:line, l:defaults)
4342
if index(b:open_tasks, l:task.uuid) >= 0
44-
call <SID>System('task uuid:'.l:task.uuid.' done')
43+
call <SID>Task('uuid:'.l:task.uuid.' done')
4544
endif
4645
endif
4746
let l:i += 1
@@ -145,7 +144,7 @@ function! vimwiki_tasks#parse_task(line, defaults)
145144
let l:match = matchlist(a:line, '\v\* \[.\]\s+(.*)\s*')
146145
let l:task.description = l:match[1]
147146
" construct the task creation command and create
148-
let l:task.task_cmd = 'task'
147+
let l:task.task_args = ''
149148
let l:task.task_meta = ''
150149
" add a project if necessary
151150
if has_key(a:defaults, 'project')
@@ -164,8 +163,8 @@ function! vimwiki_tasks#parse_task(line, defaults)
164163
" set the due in task_meta
165164
let l:task.due = l:task.due_date.'T'.l:task.due_time
166165
let l:task.task_meta .= ' due:'.l:task.due
167-
" set the dateformat in task_cmd
168-
let l:task.task_cmd .= ' rc.dateformat=Y-M-DTH:N'
166+
" set the dateformat in task_args
167+
let l:task.task_args .= ' rc.dateformat=Y-M-DTH:N'
169168
endif
170169
" get the uuid from the task if it is there, and remove it from the task description
171170
let l:task.uuid = matchstr(a: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})')
@@ -210,8 +209,8 @@ endfunction
210209

211210
function! vimwiki_tasks#load_task(uuid)
212211
let l:task = vimwiki_tasks#empty_task()
213-
let l:cmd = 'task rc.verbose=nothing rc.defaultwidth=999 rc.dateformat.info=Y-M-DTH:N rc.color=off uuid:'.a:uuid.' info | grep "^\(ID\|UUID\|Description\|Status\|Due\|Project\|Tags\)"'
214-
let l:result = split(<SID>System(l:cmd), '\n')
212+
let l:cmd = 'rc.verbose=nothing rc.defaultwidth=999 rc.dateformat.info=Y-M-DTH:N rc.color=off uuid:'.a:uuid.' info | grep "^\(ID\|UUID\|Description\|Status\|Due\|Project\|Tags\)"'
213+
let l:result = split(<SID>Task(l:cmd), '\n')
215214
for l:result_line in l:result
216215
let l:match = matchlist(l:result_line, '\v(\w+)\s+(.*)')
217216
let l:task[tolower(l:match[1])] = l:match[2]
@@ -294,6 +293,11 @@ function! s:System(cmd)
294293
return system(a:cmd)
295294
endfunction
296295

296+
function! s:Task(args)
297+
" execute task with the given args + any optional args specified by the user
298+
return system('task '.vimwiki_tasks#config('task_args', '').' '.a:args)
299+
endfunction
300+
297301
function! s:ErrorMsg(error)
298302
if a:error ==# 'TASK_DELETED'
299303
return 'Task was deleted in taskwarrior'

0 commit comments

Comments
 (0)