about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2004-07-23 13:37:42 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2004-07-23 13:37:42 +0000
commit8605ba6dacb27d48be99fd762b54aaac1a6b4958 (patch)
treefff2a34f6aa83d39a4f7d2241485af8b3ff67647
parentd8e4bb5a383a8566e7ee86466ebe057c45b03201 (diff)
downloadzsh-8605ba6dacb27d48be99fd762b54aaac1a6b4958.tar.gz
zsh-8605ba6dacb27d48be99fd762b54aaac1a6b4958.tar.xz
zsh-8605ba6dacb27d48be99fd762b54aaac1a6b4958.zip
Motoi Washida: 20179: new completions for Mac OS X
-rw-r--r--ChangeLog7
-rw-r--r--Completion/Darwin/Command/.distfiles4
-rw-r--r--Completion/Darwin/Command/_defaults66
-rw-r--r--Completion/Darwin/Command/_open12
-rw-r--r--Completion/Darwin/Type/.distfiles4
-rw-r--r--Completion/Darwin/Type/_mac_applications51
6 files changed, 144 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b007fc730..bb5fed949 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-07-23  Oliver Kiddle  <opk@zsh.org>
+
+	* Motoi Washida <a66@h8.dion.ne.jp>: 20179 (tweaked):
+	Completion/Darwin/Type/_mac_applications,
+	Completion/Darwin/Command/_open, Completion/Darwin/Command/_defaults:
+	new completions for Mac OS X
+
 2004-07-19  Oliver Kiddle  <opk@zsh.org>
 
 	* Jean-Baptiste Quenot: 20167: Completion/Unix/Command/_ant:
diff --git a/Completion/Darwin/Command/.distfiles b/Completion/Darwin/Command/.distfiles
new file mode 100644
index 000000000..78ac7b353
--- /dev/null
+++ b/Completion/Darwin/Command/.distfiles
@@ -0,0 +1,4 @@
+DISTFILES_SRC='
+.distfiles
+_defaults  _open
+'
diff --git a/Completion/Darwin/Command/_defaults b/Completion/Darwin/Command/_defaults
new file mode 100644
index 000000000..0c17c9e69
--- /dev/null
+++ b/Completion/Darwin/Command/_defaults
@@ -0,0 +1,66 @@
+#compdef defaults
+
+_defaults_domains(){
+  local str="$(_call_program domains defaults domains 2>/dev/null)"
+  local expl
+  local -a list
+  list=( ${(s/, /)str} -g -globalDomain )
+  _wanted domains expl 'defaults database domain' \
+      compadd -M 'r:|.=* r:|=*' -a list
+}
+
+_defaults_keys(){
+  local ks="$(_call_program keys defaults read "$words[2]" 2>/dev/null | sed '/^    [[:alpha:]"]/ { s/^    //; s/ = .*$//; p;}; d')"
+  local expl
+  _wanted keys expl 'key' compadd ${(f)ks}
+}
+
+_defaults(){
+  local -a _1st_arguments
+  _1st_arguments=( read read-type write rename delete domains find help )
+
+  local curcontext="$curcontext" state line expl
+
+  _arguments -A '-*' \
+    '(-currentHost)-host:host:_hosts' \
+    '(-host)-currentHost' \
+    '*::command:->subcmd' && return 0
+
+  if (( CURRENT == 1 )); then
+    _describe -t commands "command" _1st_arguments
+    return
+  fi
+
+  case $words[1] in
+    read|read-type|delete)
+      _arguments \
+        "(1)-app:application:_mac_applications" \
+        "(-app)1:domain:_defaults_domains" \
+        "2:keys:_defaults_keys"
+      ;;
+    write)
+      _arguments \
+        "(1)-app:application:_mac_applications" \
+        "(-app)1:domain:_defaults_domains" \
+        "2:key:_defaults_keys" \
+        "*::value"
+      ;;
+    rename)
+      _arguments \
+        "(1)-app:application:_mac_applications" \
+        "(-app)1:domain:_defaults_domains" \
+        "2:old key:_defaults_keys" \
+        "3:new key:_defaults_keys"
+      ;;
+    domains|help)
+      ;;
+    find)
+      _message word
+      ;;
+    *)
+      _message "unknown defaults command: $words[1]"
+      ;;
+  esac
+}
+
+_defaults "$@"
diff --git a/Completion/Darwin/Command/_open b/Completion/Darwin/Command/_open
new file mode 100644
index 000000000..9478dd562
--- /dev/null
+++ b/Completion/Darwin/Command/_open
@@ -0,0 +1,12 @@
+#compdef open
+
+local curcontext="$curcontext" state line
+
+_arguments -C \
+  '-a[specify application]:application:->open_mac_applications' \
+  '-e[open with TextEdit]' \
+  '*:files:_webbrowser'
+
+if [[ -n "$state" ]]; then
+  _mac_applications || _files
+fi
diff --git a/Completion/Darwin/Type/.distfiles b/Completion/Darwin/Type/.distfiles
new file mode 100644
index 000000000..bf2b38068
--- /dev/null
+++ b/Completion/Darwin/Type/.distfiles
@@ -0,0 +1,4 @@
+DISTFILES_SRC='
+.distfiles
+_mac_applications
+'
diff --git a/Completion/Darwin/Type/_mac_applications b/Completion/Darwin/Type/_mac_applications
new file mode 100644
index 000000000..69b23ea7b
--- /dev/null
+++ b/Completion/Darwin/Type/_mac_applications
@@ -0,0 +1,51 @@
+#autoload
+
+_mac_applications_caching_policy () {
+   # rebuild if cache is more than a day old
+   oldp=( "$1"(Nmw+1) )
+   (( $#oldp ))
+}
+
+_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 "$@"