about summary refs log tree commit diff
path: root/Completion/Darwin/Command
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Darwin/Command')
-rw-r--r--Completion/Darwin/Command/.distfiles4
-rw-r--r--Completion/Darwin/Command/_defaults66
-rw-r--r--Completion/Darwin/Command/_open12
3 files changed, 82 insertions, 0 deletions
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