mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-06-09 16:56:04 +02:00
Motoi Washida: 20179: new completions for Mac OS X
This commit is contained in:
parent
d8e4bb5a38
commit
8605ba6dac
|
@ -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:
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
DISTFILES_SRC='
|
||||
.distfiles
|
||||
_defaults _open
|
||||
'
|
|
@ -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 "$@"
|
|
@ -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
|
|
@ -0,0 +1,4 @@
|
|||
DISTFILES_SRC='
|
||||
.distfiles
|
||||
_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 "$@"
|
Loading…
Reference in New Issue