PatchHub
t

patchhub/tasks

A tiny to-do list for your terminal

0
Download

t Download tasks

Do you want to add some patches?

No patches yet. Create the first one.

Downloads with patches are built for you. It usually takes a minute or two.

History

First version

p patchhub 14d ago 7a48f5313beff170089d7463bc90f4d3d9297c3a 4 files changed +148 −0
README.md +21 −0
@@ -0,0 +1,21 @@
+# tasks
+
+A tiny to-do list for your terminal. Your tasks are saved in a file in your home folder, so they're still there next time.
+
+## Get it
+
+Click **Download** on PatchHub and pick your system (macOS, Windows or Linux). You get a single program file, with nothing to install.
+
+- **macOS:** open Terminal, then run `chmod +x tasks` and `./tasks`. The first time, you may need to allow it in System Settings → Privacy & Security.
+- **Windows:** open PowerShell in the download folder and run `.\tasks.exe`.
+- **Linux:** run `chmod +x tasks` and `./tasks`.
+
+## Use it
+
+| Command | What it does |
+|---|---|
+| `tasks add Buy milk` | Add a task |
+| `tasks` | Show open tasks |
+| `tasks done 2` | Mark task 2 as done |
+| `tasks all` | Show every task, including finished ones |
+| `tasks clear` | Remove finished tasks |
go.mod +3 −0
@@ -0,0 +1,3 @@
+module tasks
+
+go 1.22
main.go +115 −0
@@ -0,0 +1,115 @@
+// tasks is a tiny to-do list for the terminal.
+//
+// tasks add Buy milk add a task
+// tasks list open tasks
+// tasks done 2 mark task 2 as done
+// tasks all list every task, including done ones
+// tasks clear remove done tasks
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "time"
+)
+
+type task struct {
+ Text string `json:"text"`
+ Done bool `json:"done"`
+ Created time.Time `json:"created"`
+}
+
+func file() string {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ home = "."
+ }
+ return filepath.Join(home, ".tasks.json")
+}
+
+func load() []task {
+ var ts []task
+ if b, err := os.ReadFile(file()); err == nil {
+ json.Unmarshal(b, &ts)
+ }
+ return ts
+}
+
+func save(ts []task) {
+ b, _ := json.MarshalIndent(ts, "", " ")
+ if err := os.WriteFile(file(), b, 0o644); err != nil {
+ fmt.Fprintln(os.Stderr, "couldn't save tasks:", err)
+ os.Exit(1)
+ }
+}
+
+func list(ts []task, all bool) {
+ shown := 0
+ for i, t := range ts {
+ if t.Done && !all {
+ continue
+ }
+ box := "[ ]"
+ if t.Done {
+ box = "[x]"
+ }
+ fmt.Printf("%3d. %s %s\n", i+1, box, t.Text)
+ shown++
+ }
+ if shown == 0 {
+ fmt.Println("Nothing to do. Add a task with: tasks add <what to do>")
+ }
+}
+
+func main() {
+ ts := load()
+ args := os.Args[1:]
+ if len(args) == 0 {
+ list(ts, false)
+ return
+ }
+ switch args[0] {
+ case "add":
+ text := strings.TrimSpace(strings.Join(args[1:], " "))
+ if text == "" {
+ fmt.Println("What should the task say? Example: tasks add Call mom")
+ os.Exit(1)
+ }
+ ts = append(ts, task{Text: text, Created: time.Now()})
+ save(ts)
+ fmt.Printf("Added task %d: %s\n", len(ts), text)
+ case "done":
+ if len(args) < 2 {
+ fmt.Println("Which task? Example: tasks done 2")
+ os.Exit(1)
+ }
+ n, err := strconv.Atoi(args[1])
+ if err != nil || n < 1 || n > len(ts) {
+ fmt.Println("There's no task with that number.")
+ os.Exit(1)
+ }
+ ts[n-1].Done = true
+ save(ts)
+ fmt.Printf("Nice! Finished: %s\n", ts[n-1].Text)
+ case "all":
+ list(ts, true)
+ case "clear":
+ var open []task
+ for _, t := range ts {
+ if !t.Done {
+ open = append(open, t)
+ }
+ }
+ save(open)
+ fmt.Printf("Removed %d finished task(s).\n", len(ts)-len(open))
+ case "help", "-h", "--help":
+ fmt.Println("Usage: tasks [add <text> | done <number> | all | clear]")
+ default:
+ fmt.Println("Unknown command. Try: tasks help")
+ os.Exit(1)
+ }
+}
patchhub.json +9 −0
@@ -0,0 +1,9 @@
+{
+ "variants": [
+ {"id": "macos-arm64", "name": "macOS (Apple Silicon)", "toolchain": "go", "build": "GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags=-s -o dist/tasks .", "artifact": "dist/tasks"},
+ {"id": "macos-x64", "name": "macOS (Intel)", "toolchain": "go", "build": "GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags=-s -o dist/tasks .", "artifact": "dist/tasks"},
+ {"id": "windows-x64", "name": "Windows (64-bit)", "toolchain": "go", "build": "GOOS=windows GOARCH=amd64 go build -trimpath -ldflags=-s -o dist/tasks.exe .", "artifact": "dist/tasks.exe"},
+ {"id": "linux-x64", "name": "Linux (x64)", "toolchain": "go", "build": "GOOS=linux GOARCH=amd64 go build -trimpath -ldflags=-s -o dist/tasks .", "artifact": "dist/tasks"},
+ {"id": "linux-arm64", "name": "Linux (ARM64)", "toolchain": "go", "build": "GOOS=linux GOARCH=arm64 go build -trimpath -ldflags=-s -o dist/tasks .", "artifact": "dist/tasks"}
+ ]
+}