summaryrefslogtreecommitdiff
path: root/Completion/Darwin/Command/_open
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-11-12 11:47:41 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-11-12 11:47:41 +0000
commit24a68220a105c70a54baa543917e1022ae3e7a8d (patch)
treebb89747d3925cbb9c97afef53db3659ecedf027e /Completion/Darwin/Command/_open
parente4ba1a2ec8cd6b73d6e931e00e4a5d16e131a473 (diff)
downloadzsh-24a68220a105c70a54baa543917e1022ae3e7a8d.tar.gz
zsh-24a68220a105c70a54baa543917e1022ae3e7a8d.zip
improved Mac completion, from Motoi Washida
Diffstat (limited to 'Completion/Darwin/Command/_open')
-rw-r--r--Completion/Darwin/Command/_open45
1 files changed, 37 insertions, 8 deletions
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 "$@"