Skip to content

Instantly share code, notes, and snippets.

@zadr
Last active February 9, 2020 01:16
Show Gist options
  • Save zadr/fa23ac48bf0f76f5a271cda38c591971 to your computer and use it in GitHub Desktop.
Save zadr/fa23ac48bf0f76f5a271cda38c591971 to your computer and use it in GitHub Desktop.
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