<commit_before>local obj = {}

local chooser = require("hs.chooser")
local dialog = require("hs.dialog")
local styledtext = require("hs.styledtext")

local customshellrun = require("customshellrun")
local utils = require("utils")

-- print(styledtext.fontNames())

completionFn = function(choice)
    if choice == nil then
        return
    end
    if choice["id"] == "new" then
        hs.focus() -- this is needed for the textPrompt to have focus
        local button, newTask =
            dialog.textPrompt("New task", "Add new task entry", "<project> task description", "Add", "Cancel")
        if button == "Add" then
            local result = customshellrun.run("sp " .. newTask, true)
            hs.alert("➕ Added new task: +" .. newTask)
            hs.alert(result)
        end
    else
        hs.focus() -- this is needed for the textPrompt to have focus
        local button, message =
            dialog.textPrompt("Complete/Annotate task", "Enter message", "", "Done", "Annotate")
        if button == "Done" then
            hs.alert("✔ " .. choice["project"] .. ": " .. choice["task"]:gsub("%s+", "", 1))
            customshellrun.run("/usr/local/bin/task " .. choice["id"] .. " done " .. message)
        else
            hs.alert("📃 " .. choice["project"] .. ": " .. choice["task"]:gsub("%s+", "", 1) .. "\n" .. message)
            customshellrun.run("/usr/local/bin/task " .. choice["id"] .. " annotate " .. message)
        end
    end
    -- customshellrun.run("/usr/local/bin/task sync &")
end

function obj.run()
    local selecter = chooser.new(completionFn)
    selecter:placeholderText("Choose task to mark complete")

    local result = customshellrun.run("/usr/local/bin/task totn")
    local tasks = utils.split(result, "\n")

    local choices = {}

    for i = #tasks - 1, 3, -1 do
        local words = {}
        words[1], words[2], words[3] = tasks[i]:match(" ?(%d-) ([^ ]+)(.+)")

        local text =
            styledtext.new(
            words[2] .. "> " .. words[3]:gsub("%s+", "", 1),
            {
                font = {size = 16, name = "DankMonoNerdFontComplete-Regular"}
            }
        )
        table.insert(choices, 1, {["text"] = text, ["id"] = words[1], ["task"] = words[3], ["project"] = words[2]})
    end
    table.insert(
        choices,
        1,
        {<commit_msg>[hammerspoon] taskwarrior: set secondary to exec command<commit_after>local obj = {}

local chooser = require("hs.chooser")
local dialog = require("hs.dialog")
local styledtext = require("hs.styledtext")

local customshellrun = require("customshellrun")
local utils = require("utils")

-- print(styledtext.fontNames())

completionFn = function(choice)
    if choice == nil then
        return
    end
    if choice["id"] == "new" then
        hs.focus() -- this is needed for the textPrompt to have focus
        local button, newTask =
            dialog.textPrompt("New task", "Add new task entry", "<project> task description", "Add", "Cancel")
        if button == "Add" then
            local result = customshellrun.run("sp " .. newTask, true)
            hs.alert("➕ Added new task: +" .. newTask)
            hs.alert(result)
        end
    else
        hs.focus() -- this is needed for the textPrompt to have focus
        local button, message =
            dialog.textPrompt("Complete/Annotate task", "Enter message", "", "Done", "Exec")
        if button == "Done" then
            hs.alert("✔ " .. choice["project"] .. ": " .. choice["task"]:gsub("%s+", "", 1))
            customshellrun.run("/usr/local/bin/task " .. choice["id"] .. " done " .. message)
        else
            hs.alert("📃 " .. choice["project"] .. ": " .. choice["task"]:gsub("%s+", "", 1) .. "\n" .. message)
            customshellrun.run("/usr/local/bin/task " .. choice["id"] .. " " .. message)
        end
    end
    -- customshellrun.run("/usr/local/bin/task sync &")
end

function obj.run()
    local selecter = chooser.new(completionFn)
    selecter:placeholderText("Choose task to mark complete")

    local result = customshellrun.run("/usr/local/bin/task totn")
    local tasks = utils.split(result, "\n")

    local choices = {}

    for i = #tasks - 1, 3, -1 do
        local words = {}
        words[1], words[2], words[3] = tasks[i]:match(" ?(%d-) ([^ ]+)(.+)")

        local text =
            styledtext.new(
            words[2] .. "> " .. words[3]:gsub("%s+", "", 1),
            {
                font = {size = 16, name = "DankMonoNerdFontComplete-Regular"}
            }
        )
        table.insert(choices, 1, {["text"] = text, ["id"] = words[1], ["task"] = words[3], ["project"] = words[2]})
    end
    table.insert(
        choices,
        1,
        {
{'fraction_non_alphanumeric': 0.17735768903993204, 'fraction_numerical': 0.0076465590484282074, 'mean_word_length': 2.2121418826739427, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3623655', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1442, 'n_words': 359}