Last active
February 9, 2020 01:16
-
-
Save zadr/fa23ac48bf0f76f5a271cda38c591971 to your computer and use it in GitHub Desktop.
terminal's tiny todo tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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