From dc1a6e83669dd22be4542833970d3251741ba1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 16:39:56 +0300 Subject: Fix add task hotkey --- internal/task/task.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'internal/task/task.go') diff --git a/internal/task/task.go b/internal/task/task.go index 603002d..b20eef0 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -12,6 +12,8 @@ import ( "strconv" "strings" "time" + + "github.com/google/shlex" ) // Task represents a taskwarrior task as returned by `task export`. @@ -54,7 +56,7 @@ func SetDebugLog(path string) error { // Add creates a new task with the given description and tags. func Add(description string, tags []string) error { - args := []string{"add"} + var args []string for _, t := range tags { if len(t) > 0 && t[0] != '+' { t = "+" + t @@ -62,11 +64,28 @@ func Add(description string, tags []string) error { args = append(args, t) } args = append(args, description) + return AddArgs(args) +} - cmd := exec.Command("task", args...) +// AddArgs runs "task add" with the provided arguments. Each element in args +// is passed as a separate command-line argument, allowing the caller to +// specify additional modifiers like due dates or tags. +func AddArgs(args []string) error { + cmd := exec.Command("task", append([]string{"add"}, args...)...) return cmd.Run() } +// AddLine splits the given line into shell words and runs "task add" with the +// resulting arguments. This allows users to pass raw Taskwarrior parameters +// such as "due:today" directly. +func AddLine(line string) error { + fields, err := shlex.Split(line) + if err != nil { + return err + } + return AddArgs(fields) +} + // Export retrieves all tasks using `task export rc.json.array=off` and parses // the JSON output into a slice of Task structs. // Export retrieves tasks using `task export rc.json.array=off` and parses -- cgit v1.2.3 From b140c36cd8bb3d20c7211fe672b9d5674c9f0d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 16:50:46 +0300 Subject: Add generic task command hotkey --- internal/task/task.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'internal/task/task.go') diff --git a/internal/task/task.go b/internal/task/task.go index b20eef0..5f19482 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -86,6 +86,24 @@ func AddLine(line string) error { return AddArgs(fields) } +// RunArgs executes "task" with the given arguments. Each item in args is +// passed as a separate command-line argument. +func RunArgs(args []string) error { + cmd := exec.Command("task", args...) + return cmd.Run() +} + +// RunLine splits the provided line into shell words and executes "task" with +// the resulting arguments. This allows callers to run arbitrary Taskwarrior +// commands directly. +func RunLine(line string) error { + fields, err := shlex.Split(line) + if err != nil { + return err + } + return RunArgs(fields) +} + // Export retrieves all tasks using `task export rc.json.array=off` and parses // the JSON output into a slice of Task structs. // Export retrieves tasks using `task export rc.json.array=off` and parses -- cgit v1.2.3 From 8a83fbf747bda27f5859ad84c2f20a9afb753e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= <1224732+snonux@users.noreply.github.com> Date: Sun, 22 Jun 2025 16:58:00 +0300 Subject: Clean up unused RunArgs comments --- internal/task/task.go | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'internal/task/task.go') diff --git a/internal/task/task.go b/internal/task/task.go index 5f19482..b20eef0 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -86,24 +86,6 @@ func AddLine(line string) error { return AddArgs(fields) } -// RunArgs executes "task" with the given arguments. Each item in args is -// passed as a separate command-line argument. -func RunArgs(args []string) error { - cmd := exec.Command("task", args...) - return cmd.Run() -} - -// RunLine splits the provided line into shell words and executes "task" with -// the resulting arguments. This allows callers to run arbitrary Taskwarrior -// commands directly. -func RunLine(line string) error { - fields, err := shlex.Split(line) - if err != nil { - return err - } - return RunArgs(fields) -} - // Export retrieves all tasks using `task export rc.json.array=off` and parses // the JSON output into a slice of Task structs. // Export retrieves tasks using `task export rc.json.array=off` and parses -- cgit v1.2.3