diff options
-rw-r--r-- | .functions | 48 |
1 files changed, 43 insertions, 5 deletions
@@ -45,13 +45,12 @@ function gurl() { } # Syntax-highlight JSON strings or files +# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json` function json() { - if [ -p /dev/stdin ]; then - # piping, e.g. `echo '{"foo":42}' | json` - python -mjson.tool | pygmentize -l javascript - else - # e.g. `json '{"foo":42}'` + if [ -t 0 ]; then # argument python -mjson.tool <<< "$*" | pygmentize -l javascript + else # pipe + python -mjson.tool | pygmentize -l javascript fi } @@ -78,6 +77,45 @@ function codepoint() { echo # newline } +# Add note to Notes.app (OS X 10.8) +# Usage: `note 'foo'` or `echo 'foo' | note` +function note() { + local text + if [ -t 0 ]; then # argument + text="$1" + else # pipe + text=$(cat) + fi + body=$(echo "$text" | sed -E 's|$|<br>|g') + osascript >/dev/null <<EOF +tell application "Notes" + tell account "iCloud" + tell folder "Notes" + make new note with properties {name:"$text", body:"$body"} + end tell + end tell +end tell +EOF +} + +# Add reminder to Reminders.app (OS X 10.8) +# Usage: `remind 'foo'` or `echo 'foo' | remind` +function remind() { + local text + if [ -t 0 ]; then + text="$1" # argument + else + text=$(cat) # pipe + fi + osascript >/dev/null <<EOF +tell application "Reminders" + tell the default list + make new reminder with properties {name:"$text"} + end tell +end tell +EOF +} + # Manually remove a downloaded app or file from the quarantine function unquarantine() { for attribute in com.apple.metadata:kMDItemDownloadedDate com.apple.metadata:kMDItemWhereFroms com.apple.quarantine; do |