Compare commits

...

3 commits

2 changed files with 16 additions and 4 deletions

9
readme.md Normal file
View file

@ -0,0 +1,9 @@
# Taskwarrior Lua
A simple lua helper to import and export task data to and from taskwarrior using
its builtin `import` and `export` commands.
The `import` function imports data into Lua using `task export` and vice versa.
The `import` function takes an optional list of filters to pass on to task
warrior to limit which tasks are to be updated.

View file

@ -8,8 +8,11 @@ local function shellescape(str)
return "'"..str:gsub([[']], [['"'"']]).."'" return "'"..str:gsub([[']], [['"'"']]).."'"
end end
--- @class Task
--- @alias Task table --- @field description string
--- @field uuid string
--- @field due string
--- @field status "pending"|"completed"|"deleted"|"waiting"
--- Imports all tasks from Taskwarrior according to filters if given --- Imports all tasks from Taskwarrior according to filters if given
--- @param ... string Taskwarrior filters as individual strings --- @param ... string Taskwarrior filters as individual strings
@ -19,13 +22,13 @@ function taskwarrior.import(...)
for i, filter in ipairs(filters) do for i, filter in ipairs(filters) do
filters[i] = shellescape(filter) filters[i] = shellescape(filter)
end end
return json.decode(io.popen("task "..table.concat(filters, " ").." export"):read("*a")) return json.decode(io.popen("task rc.verbose: "..table.concat(filters, " ").." export"):read("*a"))
end end
--- Export tasks back into taskwarrior using the import command --- Export tasks back into taskwarrior using the import command
--- @param items Task[] Sequence of tasks to import --- @param items Task[] Sequence of tasks to import
function taskwarrior.export(items) function taskwarrior.export(items)
local handle = assert(io.popen("task import")) local handle = assert(io.popen("task rc.verbose: import"))
handle:write(json.encode(items)) handle:write(json.encode(items))
handle:close() handle:close()
end end