mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-03 22:32:12 +02:00
43061: Improve open (macOS) completion
This commit is contained in:
parent
05e4ee0587
commit
7caec474de
3 changed files with 66 additions and 20 deletions
|
@ -1,5 +1,9 @@
|
|||
2018-06-20 dana <dana@dana.is>
|
||||
|
||||
* 43061: Completion/Darwin/Command/_open,
|
||||
Completion/Unix/Command/_webbrowser: Improve open completion, adjust
|
||||
_webbrowser wording
|
||||
|
||||
* 43060: Completion/Unix/Command/_stat,
|
||||
Completion/Zsh/Command/_stat: Expand stat completion
|
||||
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
#compdef open
|
||||
|
||||
# Notes:
|
||||
# - open(1) says that -f opens the result in the default text editor. This is
|
||||
# not true; the result is always opened in TextEdit unless another option is
|
||||
# supplied to override it
|
||||
# - We no longer try to restrict files to those associated with the specified
|
||||
# app; this was a nice idea, but it's unreliable
|
||||
|
||||
_open_absolute_application_path() {
|
||||
local expl curcontext
|
||||
zstyle -T ":completion:${curcontext}:files" prefix-needed && \
|
||||
|
@ -8,34 +15,69 @@ _open_absolute_application_path() {
|
|||
}
|
||||
|
||||
_open() {
|
||||
local curcontext="$curcontext" state line expl
|
||||
local curcontext=$curcontext ret=1
|
||||
local -a context expl line state state_descr tmp
|
||||
local -A opt_args val_args
|
||||
|
||||
_arguments -C \
|
||||
'-a[specify application]: :->open_mac_applications' \
|
||||
'-e[open with TextEdit]' \
|
||||
'-f[reads input from standard input and opens with TextEdit]' \
|
||||
'*: :->open_files'
|
||||
# No +, and no -S (--args covers that)
|
||||
_arguments -s -C : \
|
||||
'(-a -b -e -f -R -t)-a+[specify application name]: :->applications' \
|
||||
'(: * -)--args[pass remaining arguments to application]:*:::argument' \
|
||||
'(-a -b -e -f -R -t)-b+[specify application bundle identifier]: :->bundle-ids' \
|
||||
'(-a -b -e -f -R -t)-e[open with TextEdit]' \
|
||||
'(-h)-f[open standard input with TextEdit or specified application]' \
|
||||
'(-R)-F[open application with fresh state]' \
|
||||
'-g[do not bring application to foreground]' \
|
||||
'(-f)-h[open library header file]' \
|
||||
'(-R)-n[always open new instance of application]' \
|
||||
'(-a -b -e -f -F -n -s -t -W --args)-R[reveal in Finder]' \
|
||||
'(-R)-s+[specify SDK name/version]: :->sdks' \
|
||||
'(-a -b -e -f -R -t)-t[open with default text editor]' \
|
||||
'(-R)-W[wait for application to exit]' \
|
||||
'(-f)*: :->files' \
|
||||
&& ret=0
|
||||
|
||||
case "$state" in
|
||||
open_mac_applications)
|
||||
case $state in
|
||||
applications)
|
||||
_alternative \
|
||||
"commands: :_mac_applications" \
|
||||
"files:: _open_absolute_application_path"
|
||||
"files:: _open_absolute_application_path" \
|
||||
&& ret=0
|
||||
;;
|
||||
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"
|
||||
bundle-ids)
|
||||
autoload -Uz zargs
|
||||
_retrieve_mac_apps
|
||||
tmp=( ${(@)_mac_apps:#/System/Library/(Private|)Frameworks/*} )
|
||||
tmp=( ${(0)"$(
|
||||
_call_program bundle-ids \
|
||||
zargs -n300 -P2 -- ${(@q)tmp} -- mdls -rn kMDItemCFBundleIdentifier
|
||||
)"} )
|
||||
tmp=( ${(@)tmp:#\(null\)} )
|
||||
_values 'bundle identifier' $tmp com.apple.TextEdit && ret=0
|
||||
;;
|
||||
files)
|
||||
if (( $+opt_args[-h] )); then
|
||||
tmp=(
|
||||
/System/Library/Frameworks/*/Headers/*.h(#q-.N:t)
|
||||
/usr/local/include/**/*.h(#q-.N:t)
|
||||
/usr/include/**/*.h(#q-.N:t)
|
||||
)
|
||||
_describe -t headers 'header file' tmp && ret=0
|
||||
else
|
||||
_webbrowser
|
||||
_webbrowser && ret=0
|
||||
fi
|
||||
;;
|
||||
sdks)
|
||||
tmp=( /Library/Developer/CommandLineTools/SDKs/*.*.sdk(#qN:t:r) )
|
||||
if (( $#tmp )); then
|
||||
_describe -t sdks 'SDK name/version' tmp && ret=0
|
||||
else
|
||||
_message -e sdks 'SDK name/version' && ret=0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
_open "$@"
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#compdef amaya arena chimera dillo dwb express galeon grail gzilla hotjava konqueror light mmm Mosaic netrik opera opera-next retawq skipstone www xmosaic zen
|
||||
|
||||
_alternative 'files:file:_files' 'urls:URL:_urls'
|
||||
_alternative 'files: :_files' 'urls: :_urls'
|
||||
|
|
Loading…
Reference in a new issue