From b0c0c6cc588c7006a9cbc4caf1a88be378a8f91b Mon Sep 17 00:00:00 2001 From: Josh Heidebrecht Date: Thu, 24 Dec 2015 00:43:14 -0700 Subject: [PATCH] Add wherefrom and settings function for osx - Fix a missing local variable definition in tab --- modules/osx/README.md | 2 ++ modules/osx/functions/_settings | 10 ++++++++ modules/osx/functions/_wherefrom | 5 ++++ modules/osx/functions/settings | 36 +++++++++++++++++++++++++++++ modules/osx/functions/tab | 2 +- modules/osx/functions/wherefrom | 39 ++++++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 modules/osx/functions/_settings create mode 100644 modules/osx/functions/_wherefrom create mode 100644 modules/osx/functions/settings create mode 100644 modules/osx/functions/wherefrom diff --git a/modules/osx/README.md b/modules/osx/README.md index d8eff0ff..beee632e 100644 --- a/modules/osx/README.md +++ b/modules/osx/README.md @@ -23,6 +23,8 @@ Functions - `osx-rm-dir-metadata` deletes .DS\_Store, \_\_MACOSX cruft. - `osx-ls-download-history` displays the Mac OS X download history. - `osx-rm-download-history` deletes the Mac OS X download history. + - `wherefrom` sets the Mac OS X download location for a file. + - `settings` changes the terminal settings for the current window. Authors ------- diff --git a/modules/osx/functions/_settings b/modules/osx/functions/_settings new file mode 100644 index 00000000..97b1f1e5 --- /dev/null +++ b/modules/osx/functions/_settings @@ -0,0 +1,10 @@ +#compdef settings + +_known_settings=$(osascript 2>/dev/null </dev/null <&2 </dev/null </dev/null < 0 )) && command="${command}; $*" -the_app=$( +local the_app=$( osascript 2>/dev/null <&2 < [file ...] +EOF +return 1 +fi + +url=$1 +shift + +while (( $# > 0 )); do + if [[ -f "$1" ]]; then + # A json plist containing the Downloaded from URL + local plist='["'"$url"'"]' + + # Convert to a hexdump representation of a binary plist + # In xxd set the max column count to avoid line breaks + local binplist=`echo -n "$plist" | plutil -convert binary1 -o - - | xxd -p -c 256` + + xattr -wx 'com.apple.metadata:kMDItemWhereFroms' "$binplist" "$1" + + else + print "$0: cannot read: $1" >&2 + success=1 + fi + shift +done