From 24a68220a105c70a54baa543917e1022ae3e7a8d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 12 Nov 2004 11:47:41 +0000 Subject: improved Mac completion, from Motoi Washida --- Completion/Darwin/Command/_open | 45 +++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'Completion/Darwin/Command/_open') 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 "$@" -- cgit 1.4.1