Skip to content

Instantly share code, notes, and snippets.

@zadr
Last active Feb 9, 2020
Embed
What would you like to do?
terminal's tiny todo tool
// 1. copy file to $PATH somewhere
// 2. chmod a+x it
// 3. run with `tttt` or `tttt [task to track]`
// 4. check out ~/Desktop/todo.txt
#!/usr/bin/env swift
import Foundation
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM d, HH:mm"
let todo: String
if CommandLine.arguments.count == 1 {
todo = dateFormatter.string(from: Date()) + ": " + (readLine(strippingNewline: false) ?? "")
} else {
todo = dateFormatter.string(from: Date()) + ": " + CommandLine.arguments[1] + "\n"
}
let desktop = NSURL.fileURL(withPath: NSSearchPathForDirectoriesInDomains(.desktopDirectory, .userDomainMask, true).first!)
let file = desktop.appendingPathComponent("todo").appendingPathExtension("txt")
let output = OutputStream(url: file, append: true)!
output.open()
output.write(todo, maxLength: todo.count)
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment