summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Darwin/Command/_fink166
-rw-r--r--Completion/Darwin/Command/_hdiutil546
-rw-r--r--Completion/Darwin/Command/_open45
-rw-r--r--Completion/Darwin/Type/_mac_applications51
-rw-r--r--Completion/Darwin/Type/_mac_files_for_application74
-rw-r--r--Completion/Darwin/Type/_retrieve_mac_apps59
6 files changed, 885 insertions, 56 deletions
diff --git a/Completion/Darwin/Command/_fink b/Completion/Darwin/Command/_fink
new file mode 100644
index 000000000..f0ff6834e
--- /dev/null
+++ b/Completion/Darwin/Command/_fink
@@ -0,0 +1,166 @@
+#compdef fink
+
+_fink_get_packages_with_cache(){
+  local cache_policy
+  zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
+  if [[ -z "$cache_policy" ]]; then
+    zstyle ":completion:${curcontext}:" cache-policy _finkpkgs_caching_policy
+  fi
+
+  typeset -g -a _fink_pkgs
+  local expl
+
+  if ( (( #_fink_pkgs == 0 )) || _cache_invalid finkpkgs) \
+       && ! _retrieve_cache finkpkgs; then
+    _fink_pkgs=(${(f)"$(
+      command fink list --tab \
+      | command grep -v '\[virtual package\]' \
+      | command sed 's/^   / n /' \
+      | command cut -f1,2
+    )"})
+    _store_cache finkpkgs _fink_pkgs
+  fi
+
+  if (( # > 0 )); then
+    local i
+    for i in "$@"; do
+      case "$i" in
+        -i) packages+=(${${(M)_fink_pkgs:#?i?*}#*	}) ;;
+        -o) packages+=(${${(M)_fink_pkgs:#(i)*}#*	}) ;;
+        -n) packages+=(${${(M)_fink_pkgs:# n *}#*	}) ;;
+      esac
+    done
+  else
+    packages=(${_fink_pkgs#*	})
+  fi
+}
+
+_fink_get_packages_without_cache(){
+  local expl
+
+  packages=(${(f)"$(
+    command fink list -t "$@" "$PREFIX" \
+    | command grep -v '\[virtual package\]' \
+    | command cut -f2
+  )"})
+}
+
+_fink_get_packages(){
+  # variable packages will be set
+  if zstyle -t ":completion:${curcontext}:" use-cache; then
+    _fink_get_packages_with_cache "$@"
+  else
+    _fink_get_packages_without_cache "$@"
+  fi
+}
+
+_finkpkgs_caching_policy(){
+  oldp=( "$1"(Nmw+1) )
+  (( $#oldp )) ||
+    [[ /sw/var/cache/apt/pkgcache.bin -nt "$1" ]] ||
+    [[ /sw/var/lib/dpkg/available -nt "$1" ]]
+}
+
+_fink(){
+  local -a _1st_arguments
+  _1st_arguments=(
+    'install:install or update packages'
+    'remove:remove packages'
+    'purge:remove packages and configuration files'
+    'update-all:update all installed packages to the latest version'
+    'list:search package name or conditions and list'
+    'apropos:search package descriptions or conditions and list'
+    'describe:display a description of the package'
+    'fetch:download package source files'
+    'fetch-all:downloads all package source files'
+    'fetch-missing:download all missing package source files'
+    'build:build .deb packages'
+    'rebuild:rebuild .deb packages'
+    'reinstall:reinstall packages'
+    'configure:rerun the fink configuration process'
+    'selfupdate:upgrade to a new fink release'
+    'validate:validate files'
+    'scanpackages:call dpkg-scanpackages'
+    'checksums:validate the MD5 digest of all tarballs'
+    'cleanup:removes obsolete package files'
+  )
+
+  local context state line expl
+  local -A opt_args
+
+  _arguments \
+    '(-h --help)'{-h,--help}'[display help text]' \
+    '(-q --quiet)'{-q,--quiet}'[causes fink to be less verbose]' \
+    '(-V --version)'{-V,--version}'[display version information]' \
+    '(-v --verbose)'{-v,--verbose}'[causes fink to be more verbose]' \
+    '(-y --yes)'{-y,--yes}'[assume default answer for interactive questions]' \
+    '*:: :->subcmds' && return 0
+
+  if (( CURRENT == 1 )); then
+    _describe -t commands "fink subcommand" _1st_arguments
+    return
+  fi
+
+  local -a packages
+
+  case "$words[1]" in
+    install|update|enable|activate|use)
+      _fink_get_packages -n -o
+      _wanted packages expl 'not installed or outdated fink package' compadd -a packages ;;
+    remove|disable|deactivate|unuse|delete|purge)
+      _fink_get_packages -i
+      _wanted packages expl 'installed package' compadd -a packages ;;
+    #update-all)
+    list)
+      _arguments \
+	'(-t --tab)'{-t,--tab}'[outputs list with tabs as field delimiter]' \
+        '(-i --installed)'{-i,--installed}'[packages currently installed]' \
+        '(-u --uptodate)'{-u,--uptodate}'[packages up to date]' \
+        '(-o --outdate)'{-o,--outdated}'[packages newer version is available]' \
+        '(-n --notinstalled)'{-n,--notinstalled}'[packages not installed]' \
+	'(-b --buildonly)'{-b,--buildonly}'[packages Build Only Depends]' \
+	'(-s --section)'{-s=,--section=}'[sections]:section name' \
+	'(-m --maintainer)'{-m=,--maintainer=}'[maintainer]:maintainer name' \
+	--tree='[tree]:tree name' \
+	'(-w --width)'{-w=,--width=}'[width of display]:number or "auto"' \
+	'(1 : -)'{-h,--help}'[display help text]' \
+	'1: :->pkgs' && return 0
+
+        if [[ "$state" == pkgs ]]; then
+          _fink_get_packages
+          _wanted packages expl 'package name hint' compadd -a packages
+        fi ;;
+    apropos)
+      _arguments \
+        '(-t --tab)'{-t,--tab}'[output the list with tabs as field delimiter]' \
+        '(-w --width)'{-w=,--width=}'[width of display]:number or "auto"' \
+        '(1 : -)'{-h,--help}'[display help text]' \
+        '1: :->pkgs' && return 0
+        
+        if [[ "$state" == pkgs ]]; then
+          _fink_get_packages
+          _wanted packages expl 'package hint' compadd -a packages
+        fi ;;
+    describe|desc|description|info)
+      _fink_get_packages
+      _wanted packages expl 'package' compadd -a packages ;;
+    #fetch)
+    #fetch-all)
+    fetch-missing)
+      _arguments \
+        '(-i --ignore-restrictive)'{-i,--ignore-restrictive}'[do not fetch packages that are "License: Restrictive"]' ;;
+    #build)
+    rebuild|reinstall)
+      _fink_get_packages
+      _wanted packages expl 'package' compadd -a packages ;;
+    #configure)
+    #selfupdate)
+    validate|check)
+      _wanted files expl 'finkinfo file' _files -g \*.info ;;
+    #scanpackages)
+    #checksums)
+    #cleanup)
+  esac
+}
+
+_fink "$@"
diff --git a/Completion/Darwin/Command/_hdiutil b/Completion/Darwin/Command/_hdiutil
new file mode 100644
index 000000000..4d4567ec6
--- /dev/null
+++ b/Completion/Darwin/Command/_hdiutil
@@ -0,0 +1,546 @@
+#compdef hdiutil
+
+# utilities
+#
+_hdiutil_disk() {
+  local -a disk_desc
+  _call_program devices hdiutil info | while read; do
+    local disk_name="${${(M)REPLY[(w)1]%/dev/disk*}#/dev/}"
+    if (( #disk_name )); then
+      disk_desc+=( "$disk_name:${${(M)REPLY%	*}#?}" )
+    fi
+  done
+  _describe -t devices disks disk_desc
+}
+
+_hdiutil_device() {
+  local -a device_desc
+  _call_program devices /usr/bin/hdiutil burn -list | while read; do
+    if [[ "$REPLY" == [:space:]#IOService:* ]]; then
+      device_desc+=( "$REPLY" )
+    fi
+  done
+  local expl
+  _wanted devices expl device compadd "$device_desc[@]"
+}
+
+_hdiutil_imagesize(){
+  local -a arr
+  local num="${PREFIX%%[^0-9]*}"
+  if [[ -n "$num" ]]; then
+    arr=(
+      "$num"b:"$(($num / 2.**11)) mega bytes"
+      "$num"k:"$(($num / 2.**10)) mega bytes"
+      "$num"m:"$(($num)) mega bytes"
+      "$num"g:"$(($num)) giga bytes"
+      "$num"t:"$(($num * 2**10)) giga bytes"
+      "$num"p:"$(($num * 2**20)) giga bytes"
+      "$num"e:"$(($num * 2**30)) giga bytes"
+    )
+  
+    local expl
+    _describe -t values "size (b, k, m, g..)" arr -V1
+  else
+    _message "size (b, k, m, g..)"
+  fi
+}
+
+_hdiutil_imageformat(){
+  local -a fmts
+  fmts=(
+    "UDRW:UDIF read/write image"
+    "UDRO:UDIF read-only image"
+    "UDZO:UDIF zlib-compressed image"
+    "UDCO:UDIF ADC-compressed image"
+    "UFBI:UDIF entire image with MD5 checksum"
+    "UDTO:DVD/CD-R master for export"
+    "UDxx:UDIF stub image"
+    "UDSP:SPARSE (growable with content)"
+    "Rdxx:NDIF read-only image (Disk Copy 6.3.3 format)"
+    "DC42:Disk Copy 4.2 image"
+  )
+  ofmts=(
+    "UDRo:UDIF read-only"
+    "UDCo:UDIF compressed"
+    "RdWr:NDIF read/write image"
+    "ROCo:NDIF compressed image"
+    "Rken:NDIF compressed"
+  )
+  _describe -t types "image format" fmts -V1 ||
+  _describe -t types "obsolete/deprecated image format" ofmts -V1 
+}
+
+_hdiutil(){
+  local -a _common_options
+  _common_options=(
+    '(: -)'-help'[display help message of a verb]'
+    '(-quiet)-verbose' '(-verbose debug)-quiet' '(-quiet)-debug'
+  )
+
+  local -A _common_usage_options
+  _common_usage_options=(
+    -shadow "-shadow:shadow file:_files -g \*.shadow"
+    -encryption "-encryption:encryption method:(CEncryptedEncoding)"
+    -stdinpass "-stdinpass[specify password from standard input]"
+    -certificate "-certificate[secondary access certificate]:certificate file:_files"
+    -cacert "-cacert[certificate authority certificate]: :_files"
+    -imagekey "*-imagekey[image key]:: :->keyvalue"
+    -srcimagekey "*-srcimagekey[source image key]:: :->keyvalue"
+    -tgtimagekey "*-tgtimagekey[target image key]:: :->keyvalue"
+    -insecurehttp "-insecurehttp[ignore SSL host validation failure]"
+    -plist "-plist[display output in plist format]"
+    -recover "-recover[keychain to unlock]:keychain file:_files -g \*.keychain"
+  )
+
+  local -a _1st_arguments
+  _1st_arguments=(
+    'help:display minimal usage information'
+    'attach:attach a disk image'
+    'mount:attach a disk image'
+    'detach:detach a disk image'
+    'eject:detach a disk image'
+    'verify:verify the checksum of a disk image'
+    'create:create a disk image'
+    'convert:convert a disk image into another format'
+    'burn:burn image to optical media'
+    'makehybrid:generate cross-platform hybrid images'
+    'compact:compacts a SPARSE disk image'
+    'info:display information about the disk image driver and attached images'
+    'load:manually load the disk image driver'
+    'checksum:calculate the specified checksum on the image data'
+    'chpass:change the passphrase for an encrypted image'
+    'unflatten:extract any UDIF metadata into resource fork'
+    'flatten:embed any resource fork into UDIF data fork'
+    'hfsanalyze:print information about an HFS/HFS+ volume'
+    'mountvol:mount a volume'
+    'unmount:unmount a volume'
+    'imageinfo:print out information about a disk image'
+    'plugins:print information about DiskImages framework plugins'
+    'internet-enable:enable or disable post-processing for the image'
+    'resize:resize partition or image'
+    'segment:segment disk image'
+    'pmap:display the partition map'
+  )
+
+  local size_spec='-size -sectors -megabytes -srcfolder -srcdir'
+
+  #
+  local curcontext="$curcontext" state line expl
+  local -A opt_args
+
+  _arguments -C '*:: :->subcmds'
+
+  if (( CURRENT == 1 )); then
+    _describe -t commands "hdiutil subcommands" _1st_arguments
+    return
+  fi
+
+  case "$words[1]" in
+    attach|mount)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-imagekey]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-plist]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "$_common_usage_options[-recover]" \
+        "(-readwrite)-readonly[force the resulting device to be read-only]" \
+        "(-readonly)-readwrite[attempt to set the device to be read/write]" \
+        "(-nokernel)-nokernel[attach with/without a helper process]" \
+        "(-kernel)-kernel[attach with/without a helper process]" \
+        "-notremovable[prevent this image from being detached]" \
+        "(-nomount)-mount[indicate whether image should be mounted]:mount?:(required optional suppressed)" \
+        "(-mount)-nomount[indicate whether image should be mounted]" \
+        "-mountroot[mount volumes in specified path]: :_directories" \
+        "-mountpoint[mount volume at specified path]: :_directories" \
+        "-union[perform a union mount]" \
+        "-private[suppress mount notifications to the rest of the system]" \
+        "-nobrowse[mark the volumes non-browsable in applications]" \
+        "-owners[enable or disable owners for HFS+ volumes]: :(on off)" \
+        "*-drivekey[key/value pair in the IOKit registry]:key=value:" \
+        "(-noverify)-verify[verify image checksums]" \
+        "(-verify)-noverify" \
+        "(-noignorebadchecksums)-ignorebadchecksums[indicate bad checksums should be ignored]" \
+        "(-ignorebadchecksums)-noignorebadchecksums" \
+        "(-noidme)-idme[perform IDME actions]" \
+        "(-idme)-noidme" \
+        "(-noidmereveal)-idmereveal[reveal the results of IDME processing]" \
+        "(-idmereveal)-noidmereveal" \
+        "(-noidmetrash)-idmetrash[put IDME images in the trash after processing]" \
+        "(-idmetrash)-noidmetrash" \
+        "(-noautoopen)-autoopen[auto-open volumes after attaching an image]" \
+        "(-autoopen)-noautoopen" \
+        "(-noautoopenro)-autoopenro[auto-open read-only volumes]" \
+        "(-autoopenro)-noautoopenro" \
+        "(-noautoopenrw)-autoopenrw[auto-open read/write volumes]" \
+        "(-autoopenrw)-noautoopenrw" \
+        "1:disk image to attach:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    detach|eject)
+      _arguments \
+        "$_common_options[@]" \
+        "-force[unmount any filesystems and detaches the image]" \
+        "1: :_hdiutil_disk" && return 0
+      ;;
+    verify)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-imagekey]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-plist]" \
+        "1:disk image to verify:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    create)
+      local fold_opts="-format -crossdev -nocrossdev -scrub -noscrub"
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-imagekey]:" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-tgtimagekey]" \
+        "$_common_usage_options[-plist]" \
+        "($size_spec $fold_opts)-size[specify size]: :_hdiutil_imagesize" \
+        "($size_spec $fold_opts)-sectors[specify size]:512 byte sectors" \
+        "($size_spec $fold_opts)-megabytes[specify size]:mega bytes" \
+        "($size_spec)-srcfolder[specify directory]: :_directories" \
+        "($size_spec)-srcdir[specify directory]: :_directories" \
+        "-align[size to which partition is aligned]:size" \
+        "-type[image type]:image type:(UDIF SPARSE)" \
+        "-fs[filesystem to make]:filesystem:(HFS+ HFS+J HFSX HFS MS-DOS UFS)" \
+        "-volname[volume name]:name" \
+        "-uid[uid of root directory]:uid in number" \
+        "-gid[gid of root directory]:gid in number" \
+        "-mode[mode of root directory]:mode" \
+        "-nouuid[suppress addiing a UUID]" \
+        "(-noautostretch)-autostretch" \
+        "(-autostretch)-noautostretch" \
+        "-stretch[max_stretch]: :_hdiutil_imagesize" \
+        "-fsargs[additional arguments to pass to newfs]:arguments" \
+        "-layout[partition layout]:partition layout:(NONE SPUD UNIVERSAL\ CD UNIVERSAL\ HD)" \
+        "-partitionType[partition type]:partition type:(Apple_HFS Apple_UFS)" \
+        "-ov[overwrite an existing file]" \
+        "-attach[attach the image after creating it]" \
+        "-format:format:_hdiutil_imageformat" \
+        "(-nocrossdev)-crossdev[cross device boundaries when copying from the source]" \
+        "(-crossdev)-nocrossdev" \
+        "(-noscrub)-scrub[skip temporary files and trashes]" \
+        "(-scrub)-noscrub" \
+        "(-noanyowners)-anyowners[allow user files being copied]" \
+        "(-anyowners)-noanyowners" \
+        "1:disk image to create:_files" && return 0
+        
+      if [[ $state = keyvalue ]]; then
+        _values 'key=value' \
+          "di-sparse-puma-compatible:(TRUE FALSE)" \
+          "di-shadow-puma-compatible:(TRUE FALSE)" \
+          "encrypted-encoding-version:version:(1 2)" \
+          "zlib-level:compression level:(1 2 3 4 5 6 7 8 9)" && return 0
+      fi
+      ;;
+    convert)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-certificate]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-tgtimagekey]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "$_common_usage_options[-plist]" \
+        "-align:size (512 byte sectors)" \
+        "-segmentSize: :_hdiutil_imagesize" \
+        "-pmap[add partition map]" \
+        "-tasks[number of tasks for compression operation]:number:" \
+        "-ov[overwrite an existing file]" \
+        "-format:format:_hdiutil_imageformat" \
+        "-o:target disk image:_files" \
+        "1:source disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+
+      if [[ $state = keyvalue ]]; then
+        _values 'key=value' \
+          "zlib-level:compression level:(1 2 3 4 5 6 7 8 9)" && return 0
+      fi
+      ;;
+    burn)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "-device[device to use for burning]:device:_hdiutil_device" \
+        "-testburn[don\'t turn on laser]" \
+        "-anydevice[allow burning to devices not qualified by Apple]" \
+        "(-eject)-noeject[don\'t eject disc after burning]" \
+        "(-noeject)-eject" \
+        "(-verifyburn)-noverifyburn[don\'t verify disc contents after burn]" \
+        "(-noverifyburn)-verifyburn" \
+        "(-addpmap)-noaddpmap[don\'t add partition map]" \
+        "(-noaddpmap)-addpmap" \
+        "(-skipfinalfree)-noskipfinalfree[don\'t skip final free partition]" \
+        "(-noskipfinalfree)-skipfinalfree" \
+        "(-nooptimizeimage)-optimizeimage[optimize filesystem for burning]" \
+        "(-optimizeimage)-nooptimizeimage" \
+        "-nounderrun[turn off buffer underrun protection]" \
+        "-forceclose[force the disc to be closed after burning]" \
+        "-speed[desired \"x-factor\"]:x_factor:(1 2 4 6 max)" \
+        "-sizequery[calculate the required size without burning anything]" \
+        "-erase[erase the media]" \
+        "-fullerase[erase all sectors of the disc]" \
+        "-list[list all burning devices with paths suitable for -device]" \
+        "1:disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    makehybrid)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "-hfs[generate an HFS+ filesystem]" \
+        "-iso[generate an ISO9660 filesystem with Rock Ridge extensions]" \
+        "-joliet[generate Joliet extensions to ISO9660]" \
+        "-hfs-blessed-directory[blessed folder for booting Mac OS X]: :_directories" \
+        "-hfs-openfolder[folder automatically opened]: :_directories" \
+        "-hfs-startupfile-size[Startup File size]:bytes" \
+        "-abstract-file[path to an ISO9660/Joliet Abstract file]: :_file" \
+        "-bibliography-file[path to a ISO9660/Joliet Bibliography file]: :_file" \
+        "-copyright-file[path to a ISO9660/Joliet Copyright file]: :_file" \
+        "-application[creator application name]:creator name" \
+        "-preparer[data preparer name]:preparer name" \
+        "-publisher[publisher name]:publisher name" \
+        "-system-id[system identifier]:system identifier" \
+        "-keep-mac-specific[keep Macintosh-specific files in non-HFS+ filesystems]" \
+        "-default-volume-name[default volume name for all filesystems]:name" \
+        "-hfs-volume-name[volume name for HFS+ filesystem]:name" \
+        "-iso-volume-name[volume name for ISO9660 filesystem]:name" \
+        "-joliet-volume-name[volume name for Joliet]:name" \
+        "-hide-all[glob expression to hide]:glob expression" \
+        "-hide-hfs[glob expression to hide in HFS+]:glob expression" \
+        "-hide-iso[glob expression to hide in ISO9660]:glob expression" \
+        "-hide-joliet[glob expression to hide in Joliet]:glob expression" \
+        "-print-size[print size estimate and quit]" \
+        "-plistin[accept command-line options as a plist on stdin]" \
+        "-ov[overwrite an existing file]" \
+        "(-noverify)-verify[verify image checksums]" \
+        "(-verify)-noverify" \
+        "(-nokernel)-nokernel[attach with a helper process]" \
+        "(-kernel)-kernel[attach without a helper process]" \
+        "-o:target disk image:_files" \
+        "1:source disk image or directory:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    compact)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "$_common_usage_options[-plist]" \
+        "1:sparse image:_files -g \*.sparseimage" && return 0
+      ;;
+    info)
+      _arguments "$_common_options[@]" \
+        "$_common_usage_options[-plist]" && return 0
+      ;;
+    load)
+      _arguments "$_common_options[@]" && return 0
+      ;;
+    checksum)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "$_common_usage_options[-plist]" \
+        "-type:image type:(UDIF-CRC32 UDIF-MD5 DC42 CRC28 CRC32 MD5)" \
+        "1:disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    chpass)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-recover]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "-oldstdinpass[specify old password from standard input]" \
+        "-newstdinpass[specify new password from standard input]" \
+        "1:disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    unflatten)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "1:disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    flatten)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "(-xml)-noxml[don\'t embed XML data for in-kernel attachment]" \
+        "(-noxml)-xml" \
+        "(-rsrcfork)-norsrcfork[don\'t embed resource fork data]" \
+        "(-norsrcfork)-rsrcfork" \
+        "1:disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    hfsanalyze)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "1:disk image or device:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    mountvol)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-plist]" \
+        "1: :_path_files -W /dev -g disk\*" && return 0
+      ;;
+    unmount)
+      _arguments \
+        "$_common_options[@]" \
+        "-force[unmount filesystem regardless of open files]" \
+        "1:device or mount point:_files" && return 0
+      ;;
+    imageinfo)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "$_common_usage_options[-plist]" \
+        "-format[just print out the image format]" \
+        "-checksum[just print out the image checksum]" \
+        "1:disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+    plugins)
+      _arguments \
+        "$_common_options[@]" "$_common_usage_options[-plist]" && return 0
+      ;;
+    internet-enable)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-plist]" \
+        "(-yes -no -query)"{-yes,-no,-query} \
+        "1:disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+      ;;
+
+    resize)
+      _arguments -C \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "$_common_usage_options[-plist]" \
+        "(-sectors)-size[specify size]: :_hdiutil_imagesize" \
+        "(-size)-sectors[specify size]:size (512 byte sectors)/min/max:" \
+        "-imageonly[only resize image file]" \
+        "-partitiononly[only resize partition(s) in the image]" \
+        "-partitionNumber[partition to resize]:partition number" \
+        "-growonly[only allow the image to grow]" \
+        "-shrinkonly[only allow the image to shrink]" \
+        "-nofinalgap[allow elimination of trailing free partition]" \
+        "-limits[displays min/current/max size]" \
+        "1:disk image:_files -g \*.dmg\(\|.bin\)" \
+        && return 0
+      ;;
+    segment)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-tgtimagekey]" \
+        "$_common_usage_options[-plist]" \
+        "(-segmentSize)-segmentCount[number of segments]:number" \
+        "(-segmentCount)-segmentSize[segment size]: :_hdiutil_imagesize" \
+        "-firstSegmentSize[first segment size]: :_hdiutil_imagesize" \
+        "-restricted[make restricted segments]" \
+        "-o[first segment name]:name" \
+        "1:source disk image:_files -g \*.dmg\(\|.bin\)" \
+        && return 0
+      ;;
+    pmap)
+      _arguments \
+        "$_common_options[@]" \
+        "$_common_usage_options[-encryption]" \
+        "$_common_usage_options[-stdinpass]" \
+        "$_common_usage_options[-srcimagekey]" \
+        "$_common_usage_options[-shadow]" \
+        "$_common_usage_options[-insecurehttp]" \
+        "$_common_usage_options[-cacert]" \
+        "-options[just print out the image checksum]: :->option" \
+        "1:disk image:_files -g \*.\(dmg\|sparseimage\)\(\|.bin\)" \
+        && return 0
+
+      case "$state" in
+        option)
+          _values -s '' option \
+            "r[process all without modification]" \
+            "x[process 2K & 512 entries and merge]" \
+            "s[return all quantities in sectors]" \
+            "S[sort all entries by block number]" \
+            "g[account for all unmapped space]" \
+            "c[combine adjacent freespace entries]" \
+            "f[extend last partition to device end]" \
+            "v[synthesize single volumes as a single partition entry]" \
+            "k[skip zero length entries]" \
+            "K[skip all free & void partitions]" \
+            "m[merge small free partitions into a previous partition]" \
+            "i[ignore small free partitions caused by block alignment]"
+          ;;
+      esac
+      ;;
+    *)
+      _message "unknown hdiutil command: $words[1]"
+      _default
+      ;;
+  esac
+  return 1
+}
+
+_hdiutil "$@"
diff --git a/Completion/Darwin/Command/_open b/Completion/Darwin/Command/_open
index 9478dd562..3926276c6 100644
--- a/Completion/Darwin/Command/_open
+++ b/Completion/Darwin/Command/_open
@@ -1,12 +1,41 @@
 #compdef open
 
-local curcontext="$curcontext" state line
+_open_absolute_application_path() {
+  local expl curcontext
+  zstyle -T ":completion:${curcontext}:files" prefix-needed && \
+    [[ "$PREFIX" != [/~]* && compstate[nmatches] -ne 0 ]] && return 1
+  _wanted files expl 'application file' _path_files -P "$PREFIX[1]" -W /
+}
 
-_arguments -C \
-  '-a[specify application]:application:->open_mac_applications' \
-  '-e[open with TextEdit]' \
-  '*:files:_webbrowser'
+_open() {
+  local curcontext="$curcontext" state line expl
 
-if [[ -n "$state" ]]; then
-  _mac_applications || _files
-fi
+  _arguments -C \
+    '-a[specify application]: :->open_mac_applications' \
+    '-e[open with TextEdit]' \
+    '-f[Reads input from standard input and opens with TextEdit]' \
+    '*: :->open_files'
+
+  case "$state" in
+    open_mac_applications)
+      _alternative \
+        "commands: :_mac_applications" \
+        "files:: _open_absolute_application_path"
+      ;;
+    open_files)
+      local app
+      if [[ -n "$words[(r)-a]" ]]; then
+        app="${(Q)words[words[(i)-a] + 1]}"
+      elif [[ -n "$words[(r)-e]" || -n "$words[(r)-f]" ]]; then
+        app="Text Edit"
+      fi
+      if [[ -n "$app" ]]; then
+        _wanted files expl "file for $app" _mac_files_for_application "$app"
+      else
+        _webbrowser
+      fi
+      ;;
+  esac
+}
+
+_open "$@"
diff --git a/Completion/Darwin/Type/_mac_applications b/Completion/Darwin/Type/_mac_applications
index 69b23ea7b..ac1df46c1 100644
--- a/Completion/Darwin/Type/_mac_applications
+++ b/Completion/Darwin/Type/_mac_applications
@@ -1,51 +1,6 @@
 #autoload
 
-_mac_applications_caching_policy () {
-   # rebuild if cache is more than a day old
-   oldp=( "$1"(Nmw+1) )
-   (( $#oldp ))
-}
+_retrieve_mac_apps
 
-_mac_applications() {
-  [[ $PREFIX = */* ]] && return 1
-
-  local cache_policy
-  zstyle -s ":completion:*:*:$service:*" cache-policy cache_policy
-  if [[ -z "$cache_policy" ]]; then
-    zstyle ":completion:*:*:$service:*" cache-policy _mac_applications_caching_policy
-  fi
-
-  if ( [[ ${+apps} -eq 0 ]] || _cache_invalid Mac_applications ) \
-        && ! _retrieve_cache Mac_applications; then
-    local app_pattern="*.app"
-
-    local -a app_path 
-    zstyle -s ":completion:${curcontext}:commands" application-dir app_path
-    if [[ -z "$app_path" ]]; then
-      local -a apdptn
-      apdptn="((*~$app_pattern~Data~plugins~*Fonts~Contents)/)#"
-      app_path=({{/,/Developer,/Network,"$HOME"}/Applications/,"/Applications (Mac OS 9)/"}${~apdptn} "$HOME"/Desktop/{,*~${~app_pattern}(/)})
-    fi
-
-    local -a apps
-
-    if ! zstyle -t ":completion:${curcontext}:commands" ignore-extention; then
-      apps=("${apps[@]}" "${app_path[@]}"/${~app_pattern})
-    fi
-
-    if ! zstyle -t ":completion:${curcontext}:commands" ignore-cfm; then
-      local capps
-      capps="`awk '/^Joy\!peffpwpc/ {print FILENAME; }; { nextfile }' ${app_path}/(*~*.?~*.??~*.???~*.????)(^/)`"
-      apps=("${apps[@]}" "${(f)capps}")
-    fi
-
-    typeset -U apps
-    apps=("${apps[@]:t:r}")
-    _store_cache Mac_applications apps
-  fi
-
-  local expl
-  _wanted commands expl 'mac os x application' compadd -a apps
-}
-
-_mac_applications "$@"
+local expl
+_wanted commands expl 'Mac OS X application' compadd -- "${(@)${_mac_apps[@]:t}%.app}"
diff --git a/Completion/Darwin/Type/_mac_files_for_application b/Completion/Darwin/Type/_mac_files_for_application
new file mode 100644
index 000000000..cd4c7860b
--- /dev/null
+++ b/Completion/Darwin/Type/_mac_files_for_application
@@ -0,0 +1,74 @@
+#autoload
+
+_mac_rsrc_check() {
+  [[ ! -s "$REPLY/..namedfork/rsrc" ]] && return 1
+  if [[ -x /Developer/Tools/GetFileInfo ]]; then
+    local ftype="$(command /Developer/Tools/GetFileInfo -t $REPLY)"
+    ftype="${ftype//\"/}"
+    [[ -n "$types[(r)$ftype]" ]]
+  else
+      grep --quiet "\(${(j/\|/)types}\)" "$REPLY/..namedfork/rsrc"
+  fi
+}
+
+_mac_parse_info_plist() {
+  # For now, awk is used because builtin function "read" was too slow.
+  # '<' is used for the delimiter because some Info.plist files use CR as
+  # newline but read doesn't treat them as so
+  local s='
+    BEGIN { RS="<" }
+      /^key>/ { sub(/key>/, ""); reading_key=$0 }
+      /^string>/ {
+        sub(/string>/, "")
+        if (reading_key == "CFBundleTypeExtensions") exts=exts " \"" $0 "\""
+        if (reading_key == "CFBundleTypeOSTypes") types=types " \"" $0 "\""
+      }
+      END {
+        print "exts=(" exts ")\ntypes=(" types ")"
+      }
+    '
+    command awk $s "$app_path/Contents/Info.plist" | while read; do
+      eval "$REPLY"
+    done
+}
+
+# Try to complete files for the specified application.
+_mac_files_for_application() {
+  local -a opts
+  zparseopts -D -a opts q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+:
+
+  local app_path
+  _retrieve_mac_apps
+  app_path="${_mac_apps[(r)*/$1(|.app)]:-$1}"
+
+  local -a glob_patterns
+  glob_patterns=()
+
+  # Try to get extentions from "Info.plist" XML file.
+  if [[ -f "$app_path/Contents/Info.plist" ]]; then
+    local -a exts types
+    _mac_parse_info_plist
+
+    if [[ -n "$exts[(r)\*]" ]]; then
+      glob_patterns=( "*" )
+    else
+      if (( #exts != 0 )); then
+        glob_patterns+=( "*.(${(j/|/)exts})(N)" )
+      fi
+
+      if (( #types != 0 )); then
+        glob_patterns+=( "^*.[[:alnum:]]##(.Ne:_mac_rsrc_check:)" )
+      fi
+    fi
+  else
+    glob_patterns=( "*" )
+  fi
+
+  case ${#glob_patterns} in
+    0) return 1 ;;
+    1) _files "$opts[@]" -g "$glob_patterns[0]" ;;
+    *) _files "$opts[@]" -g "{${(j/,/)glob_patterns}}" ;;
+  esac
+}
+
+_mac_files_for_application "$@"
diff --git a/Completion/Darwin/Type/_retrieve_mac_apps b/Completion/Darwin/Type/_retrieve_mac_apps
new file mode 100644
index 000000000..cef83913f
--- /dev/null
+++ b/Completion/Darwin/Type/_retrieve_mac_apps
@@ -0,0 +1,59 @@
+#autoload
+
+# Find paths of applications and preserve them into _mac_apps.
+# Used by _mac_applications and _mac_files_for_application.
+
+_mac_apps_caching_policy () {
+   # Rebuild if cache is more than a day old
+   oldp=( "$1"(Nmw+1) )
+   (( $#oldp ))
+}
+
+_retrieve_mac_apps() {
+  local cache_policy
+  zstyle -s ":completion:*:*:$service:*" cache-policy cache_policy
+  if [[ -z "$cache_policy" ]]; then
+    zstyle ":completion:*:*:$service:*" cache-policy _mac_apps_caching_policy
+  fi
+
+  if ( [[ ${+_mac_apps} -eq 0 ]] || _cache_invalid Mac_applications ) \
+        && ! _retrieve_cache Mac_applications; then
+
+    # Get directories which may contain applications
+    typeset -aU app_dir 
+    if [[ -z "$app_dir" ]] && \
+      ! zstyle -s ":completion:${curcontext}:commands" application-dir app_dir
+    then
+      typeset -a app_dir_stop_pattern app_dir_root
+      app_dir_stop_pattern=( "*.app" "contents#" "*data" "*plugins#" "*plug?ins#" "fonts#" "document[[:alpha:]]#" "*help" "resources#" "images#" "*configurations#" )
+      app_dir_root=( {,/Developer,/Network,"$HOME"}/{Applications*(N),Desktop} )
+      typeset app_dir_pattern
+      app_dir_pattern="(^(#i)(${(j/|/)app_dir_stop_pattern}))"
+      app_dir=( ${^app_dir_root}/(${~app_dir_pattern}/)#(N) )
+    fi
+
+    typeset -g -Ua _mac_apps
+    local -a app_result
+
+    # Get application bundles
+    if ! zstyle -t ":completion:${curcontext}:commands" ignore-bundle; then
+      app_result=( ${^app_dir}*/Contents/(MacOS|MacOSClassic)(N) )
+      _mac_apps+=( ${app_result[@]%/Contents/MacOS*} )
+    fi
+
+    # Get single file applications
+    if ! zstyle -t ":completion:${curcontext}:commands" ignore-single; then
+      autoload -U zargs
+      local app_cand nargs envvars
+      app_cand=( ${^app_dir}^*.[a-z]#/..namedfork/rsrc(.UrN,.RN^U) )
+      envvars="$(builtin typeset -x)"
+      nargs=$(( $(command sysctl -n kern.argmax) - $#envvars - 2048 ))
+      app_result="$(zargs --max-chars $nargs ${app_cand[@]} -- grep -l APPL)"
+      _mac_apps+=( ${${(f)app_result}%/..namedfork/rsrc} )
+    fi
+
+    _store_cache Mac_applications _mac_apps
+  fi
+}
+
+_retrieve_mac_apps "$@"