From 0f0b602415961aa9ca069c9719a0fbb4bbb9941f Mon Sep 17 00:00:00 2001 From: dana Date: Fri, 5 Jan 2018 14:26:17 -0600 Subject: 42231: new completion functions for simple utilities belonging to the 'Darwin' and 'Linux' groups. --- Completion/Darwin/Command/_caffeinate | 12 +++++ Completion/Darwin/Command/_mdfind | 29 ++++++++++++ Completion/Darwin/Command/_mdls | 9 ++++ Completion/Darwin/Command/_mdutil | 19 ++++++++ Completion/Darwin/Command/_nvram | 30 +++++++++++++ Completion/Darwin/Command/_osascript | 34 ++++++++++++++ Completion/Darwin/Command/_pbcopy | 30 +++++++++++++ Completion/Darwin/Command/_plutil | 53 ++++++++++++++++++++++ Completion/Darwin/Command/_say | 85 +++++++++++++++++++++++++++++++++++ Completion/Darwin/Command/_scselect | 39 ++++++++++++++++ Completion/Darwin/Command/_scutil | 56 +++++++++++++++++++++++ Completion/Darwin/Command/_sw_vers | 6 +++ 12 files changed, 402 insertions(+) create mode 100644 Completion/Darwin/Command/_caffeinate create mode 100644 Completion/Darwin/Command/_mdfind create mode 100644 Completion/Darwin/Command/_mdls create mode 100644 Completion/Darwin/Command/_mdutil create mode 100644 Completion/Darwin/Command/_nvram create mode 100644 Completion/Darwin/Command/_osascript create mode 100644 Completion/Darwin/Command/_pbcopy create mode 100644 Completion/Darwin/Command/_plutil create mode 100644 Completion/Darwin/Command/_say create mode 100644 Completion/Darwin/Command/_scselect create mode 100644 Completion/Darwin/Command/_scutil create mode 100644 Completion/Darwin/Command/_sw_vers (limited to 'Completion/Darwin') diff --git a/Completion/Darwin/Command/_caffeinate b/Completion/Darwin/Command/_caffeinate new file mode 100644 index 000000000..9e361a5bd --- /dev/null +++ b/Completion/Darwin/Command/_caffeinate @@ -0,0 +1,12 @@ +#compdef caffeinate + +_arguments -s -S : \ + '-d[prevent display sleep]' \ + '-i[prevent system idle sleep]' \ + '-m[prevent disk idle sleep]' \ + '-s[prevent system sleep (AC power only)]' \ + '-u[declare that user is active]' \ + '(:)-t[specify assertion timeout value]:timeout (seconds)' \ + '(:)-w[wait for specified PID]: :_pids' \ + '(-)1: : _command_names -e' \ + '(-)*::command argument' diff --git a/Completion/Darwin/Command/_mdfind b/Completion/Darwin/Command/_mdfind new file mode 100644 index 000000000..b38b0ee91 --- /dev/null +++ b/Completion/Darwin/Command/_mdfind @@ -0,0 +1,29 @@ +#compdef mdfind + +local ret=1 +local -a context line state state_descr tmp +local -A opt_args val_args + +_arguments -s -S : \ + '(-count)-0[separate result paths by NUL]' \ + '(-0)-count[display count of results instead of paths]' \ + '(-literal)-interpret[interpret query as if entered in Spotlight search field]' \ + '(-interpret)-literal[interpret query as literal query string]' \ + '-live[provide live updates to query results]' \ + '-onlyin[limit search to specified directory]: :_directories' \ + '(: -s)*-name[search for files with names matching specified string]:file name string' \ + '-reprint[reprint -live results on update]' \ + '(: -name)-s[show contents of specified smart folder]: :->smart-folders' \ + '(-s -name)1: :_guard "^-*" "query"' \ +&& ret=0 + +[[ $state == smart-folders ]] && { + tmp=( "$HOME/Library/Saved Searches/"*.savedSearch(-.N:r:t) ) + if (( $#tmp )); then + _values 'smart folder' $tmp && ret=0 + else + _message 'smart folder' && ret=0 + fi +} + +return ret diff --git a/Completion/Darwin/Command/_mdls b/Completion/Darwin/Command/_mdls new file mode 100644 index 000000000..853cafd08 --- /dev/null +++ b/Completion/Darwin/Command/_mdls @@ -0,0 +1,9 @@ +#compdef mdls + +# Note: The inconsistent use of the -o+ option variant here is deliberate +_arguments -s -S : \ + '*'{-n+,-name}'[restrict output to specified attribute]:attribute' \ + '(-p -plist)-nullMarker[specify string used for null values]:string' \ + '(-p -r -nullMarker -plist -raw)'{-p,-plist}'[output in XML plist format to specified file]:output file:_files' \ + '(-p -r -plist -raw)'{-r,-raw}'[print raw (NUL-delimited) attribute data]' \ + '*: :_files' diff --git a/Completion/Darwin/Command/_mdutil b/Completion/Darwin/Command/_mdutil new file mode 100644 index 000000000..abac690ac --- /dev/null +++ b/Completion/Darwin/Command/_mdutil @@ -0,0 +1,19 @@ +#compdef mdutil + +# @todo This isn't fully comprehensive, but it's unclear from the documentation +# how some of these options are meant to work together or what kind of arguments +# they expect + +local -a volumes=( / /Volumes/*(N) ) + +_arguments -s -S : \ + '(-V)-a[apply to all volumes]' \ + '-d[disable Spotlight activity]' \ + '-E[erase and rebuild index]' \ + '-i[toggle indexing status]:indexing status:(on off)' \ + '-p[publish metadata]' \ + '-s[print indexing status]' \ + '(: -)-t[resolve files from specified file ID]:file ID, volume path, or device ID: :file ID' \ + "(-a)-V[apply to stores on specified volume]:volume:(${(j< >)${(@q-)volumes}})" \ + '-v[output verbosely]' \ + "*:volume:(${(j< >)${(@q-)volumes}})" diff --git a/Completion/Darwin/Command/_nvram b/Completion/Darwin/Command/_nvram new file mode 100644 index 000000000..8158eb9d2 --- /dev/null +++ b/Completion/Darwin/Command/_nvram @@ -0,0 +1,30 @@ +#compdef nvram + +local ret=1 +local -a context line state state_descr tmp +local -A opt_args val_args + +# Note: -x can only be used with -f/-p, but must be used first to have effect +_arguments -s : \ + '(: -)-c[delete all NVRAM variables]' \ + '(: -)-d[delete specified NVRAM variable]: :->variables-ro' \ + '(: -)-f[set NVRAM variables from file]: :_files' \ + '(: -)-p[print all NVRAM variables]' \ + '(-c -d)-x[use XML format for input and output]' \ + '(-)*: :->variables-rw' \ +&& ret=0 + +[[ $state == variables-* ]] && { + tmp=( ${${(f)"$( command $service -p )"}%%[[:space:]]*} ) + + [[ $state == variables-rw ]] && + tmp=( ${^tmp}'::NVRAM variable value' ) + + if (( $#tmp )); then + _values -w 'NVRAM variable' $tmp && ret=0 + else + _message 'NVRAM variable' && ret=0 + fi +} + +return ret diff --git a/Completion/Darwin/Command/_osascript b/Completion/Darwin/Command/_osascript new file mode 100644 index 000000000..5e4a5f70c --- /dev/null +++ b/Completion/Darwin/Command/_osascript @@ -0,0 +1,34 @@ +#compdef osascript + +local ret=1 +local -a context line state state_descr tmp +local -A opt_args val_args + +_arguments -s -S : \ + '-l+[specify script language]: :->languages' \ + '(:)*-e+[execute specified line of script]:script' \ + '-i[run interactively]' \ + '*-s+[specify output style]: :->modifiers' \ + '(-e)1:script file:_files' \ +&& ret=0 + +case $state in + languages) + # So far, the three languages specified here are the only ones supported, + # but adding the output of osalang makes this future-proof + _values 'script language' \ + AppleScript JavaScript 'Generic Scripting System' \ + ${(f)"$( command osalang 2> /dev/null )"} \ + && ret=0 + ;; + modifiers) + _values -S '' 'output modifier flag' \ + 'h[print values in human-readable form]' \ + 's[print values in recompilable source form]' \ + 'e[print script errors to stderr]' \ + 'o[print script errors to stdout]' \ + && ret=0 + ;; +esac + +return ret diff --git a/Completion/Darwin/Command/_pbcopy b/Completion/Darwin/Command/_pbcopy new file mode 100644 index 000000000..fd60f00cc --- /dev/null +++ b/Completion/Darwin/Command/_pbcopy @@ -0,0 +1,30 @@ +#compdef pbcopy pbpaste + +local ret=1 +local -a context line state state_descr args +local -A opt_args val_args + +args=( + '(-)-help[display help information]' + '-pboard[specify pasteboard to copy to or paste from]: :->pboards' +) +[[ $service == pbpaste ]] & args+=( + '-Prefer[specify type of data to prefer when pasting]: :->dtypes' +) + +_arguments : $args && ret=0 + +case $state in + dtypes) + _values 'data type' \ + 'txt[plain text]' \ + 'rtf[rich text]' \ + 'ps[encapsulated PostScript]' \ + && ret=0 + ;; + pboards) + _values pasteboard general ruler find font && ret=0 + ;; +esac + +return ret diff --git a/Completion/Darwin/Command/_plutil b/Completion/Darwin/Command/_plutil new file mode 100644 index 000000000..8138a5c5e --- /dev/null +++ b/Completion/Darwin/Command/_plutil @@ -0,0 +1,53 @@ +#compdef plutil + +local ret=1 k v +local -a context line state state_descr tmp fmts=( xml1 binary1 json ) +local -A opt_args val_args types=( + -bool 'boolean' + -data 'base64-encoded data' + -date 'date (XML property-list format)' + -float '64-bit float' + -integer '64-bit integer' + -json 'JSON fragment' + -xml 'XML property list' +) + +_arguments -s -S : \ + '(: -)-help[display help information]' \ + '(-p -r)-s[suppress normal output]' \ + '*:input file:_files' \ + - set1 \ + '-lint[check input for syntax errors]' \ + - set2 \ + "(-extract -insert -replace -remove)-convert[convert to specified format]:output format:(${(j< >)fmts})" \ + "(-convert -insert -replace -remove)-extract[extract value at specified key path from property list]: :->k:output format:(${(j< >)fmts})" \ + '(-convert -extract -replace -remove)-insert[insert value at specified key path into property list]: :->k: :->t: :->v' \ + '(-convert -extract -insert -remove)-replace[replace value at specified key path in property list]: :->k: :->t: :->v' \ + '(-convert -extract -insert -replace)-remove[remove value at specified key path from property list]: :->k' \ + '(-o -extract -insert -replace -remove)-e[specify output file extension]:output file extension' \ + '(-e -extract -insert -replace -remove)-o[specify output file]:output file:_files' \ + '(-r -s)-p[pretty-print property list]' \ + '(-p -s)-r[pretty-print JSON]' \ +&& ret=0 + +case $state in + k) _message 'key path' && ret=0 ;; + t) + tmp=() + for k v in ${(kv)types}; do + tmp+=( "${k}[${v}]" ) + done + _values 'value type' $tmp && ret=0 + ;; + v) + if [[ $words[(CURRENT - 1)] == -bool ]]; then + _values $types[-bool] YES NO true false && ret=0 + elif (( $+types[$words[(CURRENT - 1)]] )); then + _message $types[$words[(CURRENT - 1)]] && ret=0 + else + _message value && ret=0 + fi + ;; +esac + +return ret diff --git a/Completion/Darwin/Command/_say b/Completion/Darwin/Command/_say new file mode 100644 index 000000000..d687cfa11 --- /dev/null +++ b/Completion/Darwin/Command/_say @@ -0,0 +1,85 @@ +#compdef say + +local ret=1 +local -a context line state state_descr tmp +local -A opt_args val_args + +_arguments -s -S : \ + '(-a --audio-device)'{-a+,--audio-device=}'[specify audio device]: :->devices' \ + '--bit-rate=[specify bit rate]: :->bit-rates' \ + '--channels=[specify number of channels]:number of channels' \ + '--data-format=[specify output data format]: :->data-formats' \ + '(: -f --input-file)'{-f+,--input-file=}'[specify input file]:input file:_files' \ + '--file-format=[specify output file format]: :->file-formats' \ + '(-i --interactive)-i[display/highlight text as it is spoken]' \ + '(-i --interactive)--interactive=[display/highlight text as it is spoken]:: :->markups' \ + '(-o --output-file)'{-o+,--output-file=}'[specify output file]:output file:_files' \ + '(-n --network-send)'{-n+,--network-send=}'[specify network service/port]:network service/port' \ + '--progress[display progress meter]' \ + '--quality=[specify converter quality level]:quality level (0-127)' \ + '(-r --rate)'{-r+,--rate=}'[specify speech rate]:speech rate (words per minute)' \ + '(-v --voice)'{-v+,--voice=}'[specify voice]: :->voices' \ + '(-f)*: :_guard "^-*" "text to speak"' \ +&& ret=0 + +case $state in + bit-rates) + # A file format must have already been provided in order to complete these; + # also, not every file format supports bit-rate values + (( $+opt_args[--file-format] )) && { + tmp=( ${(f)"$( + command $service \ + --file-format=${opt_args[--file-format]##*:} \ + --bit-rate='?' 2> /dev/null + )"} ) + tmp=( ${tmp//[[:space:]]##/} ) + } + if (( $#tmp )); then + _values 'bit rate' $tmp && ret=0 + else + _message 'bit rate' && ret=0 + fi + ;; + data-formats) + # A file format must have already been provided in order to complete these + if (( ! $+opt_args[--file-format] )); then + _message 'data format' && ret=0 + else + tmp=( ${(f)"$( + command $service \ + --file-format=${opt_args[--file-format]##*:} \ + --data-format='?' 2> /dev/null + )"} ) + tmp=( ${tmp//:/\\:} ) + tmp=( ${^tmp/[[:space:]]##/[}\] ) + _values 'data format' $tmp && ret=0 + fi + ;; + devices) + tmp=( ${(f)"$( command $service -a '?' 2> /dev/null )"} ) + tmp=( ${tmp##[[:space:]]#[0-9]##[[:space:]]##} ) + tmp=( ${tmp//:/\\:} ) + _values 'audio device name or ID' $tmp && ret=0 + ;; + file-formats) + tmp=( ${(f)"$( command $service --file-format='?' 2> /dev/null )"} ) + tmp=( ${tmp%%[[:space:]]##\(.*} ) + tmp=( ${tmp//:/\\:} ) + tmp=( ${^tmp/[[:space:]]##/[}\] ) + _values 'file format' $tmp && ret=0 + ;; + markups) + tmp=( bold smso smul ${(k)terminfo} ) + _alternative \ + 'colors:color:(black red green yellow blue magenta cyan white)' \ + "capabilities:terminfo capability:( ${(j< >)tmp} )" \ + && ret=0 + ;; + voices) + tmp=( ${(f)"$( command $service -v '?' 2> /dev/null )"} ) + tmp=( ${tmp%%[[:space:]](#c2,)*} ) + _values voice $tmp && ret=0 + ;; +esac + +return ret diff --git a/Completion/Darwin/Command/_scselect b/Completion/Darwin/Command/_scselect new file mode 100644 index 000000000..79df2f981 --- /dev/null +++ b/Completion/Darwin/Command/_scselect @@ -0,0 +1,39 @@ +#compdef scselect + +local ret=1 u l +local -a context line state state_descr tmp loc1 loc2 +local -A opt_args + +_arguments -s -S : \ + '-n[delay changing until next boot]' \ + '1: :->locations' \ +&& ret=0 + +[[ $state == locations ]] && { + # For some reason scselect expects location names to be encoded in Mac OS + # Roman; in order to prevent completed arguments from breaking the tool, we'll + # insert the UUID instead if the name would contain incompatible characters + tmp=( ${(f)"$( command $service 2> /dev/null )"} ) + tmp=( ${tmp[2,-1]} ) + tmp=( ${tmp##[*[:space:]]##} ) + tmp=( ${tmp//:/\\:} ) + tmp=( ${tmp/[[:space:]]##\(/$'\0'} ) + tmp=( ${tmp%\)} ) + + for u l in "${(@0)tmp}"; do + loc1+=( "${l}:${u}" ) + if [[ $l == [[:ascii:]]## ]]; then + loc2+=( $l ) + else + loc2+=( $u ) + fi + done + + if (( $#loc1 )); then + _describe location loc1 loc2 && ret=0 + else + _message location && ret=0 + fi +} + +return ret diff --git a/Completion/Darwin/Command/_scutil b/Completion/Darwin/Command/_scutil new file mode 100644 index 000000000..6c0a84d64 --- /dev/null +++ b/Completion/Darwin/Command/_scutil @@ -0,0 +1,56 @@ +#compdef scutil + +local ret=1 +local -a context line state state_descr +local -A opt_args val_args + +# Don't complete host names unless we have -r (this is weird, but the obvious +# alternative (exclusion sets) currently doesn't work properly with option +# stacking) +(( ! $words[(I)-*] || ($words[(I)-W] && ! $words[(I)-r]) )) && +: ${PREFIX:=-} + +# @todo We could complete nc-cmd arguments better if we wanted to +_arguments -s -S -A '-*' : \ + + '(g1)' \ + '(: -)--dns[display current DNS configuration]' \ + '(: -)--get[display specified preference]: :->prefs' \ + '(: -)--nc[interact with VPN connections]: :->nc-cmd:*:argument' \ + '(: -)--prefs[interface with raw preference data]:preference file:_files' \ + '(: -)--proxy[display current proxy configuration]' \ + '(: -)--set[set specified preference]: :->prefs:value' \ + + g2 \ + '(g1 g3)-r[check network reachability]' \ + '(g1 g3)-W[monitor (watch) network reachability]' \ + '(g1 g3)1:host:_hosts' \ + '(g1 g3)2::host:_hosts' \ + + g3 \ + '(g1 g2)-w[wait for key to exist in dynamic store]' \ + '(g1 g2)-t+[specify timeout]:timeout (seconds)' \ +&& ret=0 + +case $state in + nc-cmd) + _values command \ + 'disablevpn[disable specified service or VPN application type]' \ + 'enablevpn[enable specified service or VPN application type]' \ + 'help[display command help]' \ + 'list[list services]' \ + 'ondemand[display VPN on-demand information]' \ + 'resume[resume specified service]' \ + 'select[make specified service active]' \ + 'show[display configuration information for specified service]' \ + 'start[start specified service]' \ + 'statistics[display statistics for specified service]' \ + 'status[display status for specified service]' \ + 'stop[stop specified service]' \ + 'suspend[suspend specified service]' \ + 'trigger[trigger VPN on-demand with specified host]' \ + && ret=0 + ;; + prefs) + _values preference ComputerName HostName LocalHostName && ret=0 + ;; +esac + +return ret diff --git a/Completion/Darwin/Command/_sw_vers b/Completion/Darwin/Command/_sw_vers new file mode 100644 index 000000000..11814e0b0 --- /dev/null +++ b/Completion/Darwin/Command/_sw_vers @@ -0,0 +1,6 @@ +#compdef sw_vers + +_arguments : \ + '(-)-buildVersion[display build version only]' \ + '(-)-productName[display product name only]' \ + '(-)-productVersion[display product version only]' -- cgit 1.4.1