local json = require "cjson" local taskwarrior = {} --- @param str string --- @return string local function shellescape(str) return "'"..str:gsub([[']], [['"'"']]).."'" end --- @alias Task table --- Imports all tasks from Taskwarrior according to filters if given --- @param ... string Taskwarrior filters as individual strings --- @return Task[] tasks Sequence listing all tasks function taskwarrior.import(...) local filters = {...} for i, filter in ipairs(filters) do filters[i] = shellescape(filter) end return json.decode(io.popen("task "..table.concat(filters, " ").." export"):read("*a")) end --- Export tasks back into taskwarrior using the import command --- @param items Task[] Sequence of tasks to import function taskwarrior.export(items) local handle = assert(io.popen("task import")) handle:write(json.encode(items)) handle:close() end return taskwarrior