42231: new completion functions for simple utilities belonging to the 'Darwin' and 'Linux' groups.

This commit is contained in:
dana 2018-01-05 14:26:17 -06:00 committed by Oliver Kiddle
parent 0c5f851021
commit 0f0b602415
17 changed files with 528 additions and 1 deletions

View file

@ -1,5 +1,23 @@
2018-01-05 Oliver Kiddle <okiddle@yahoo.co.uk>
* dana: 42231: Completion/Darwin/Command/_caffeinate,
Completion/Darwin/Command/_mdfind,
Completion/Darwin/Command/_mdls,
Completion/Darwin/Command/_mdutil,
Completion/Darwin/Command/_nvram,
Completion/Darwin/Command/_osascript,
Completion/Darwin/Command/_pbcopy,
Completion/Darwin/Command/_plutil,
Completion/Darwin/Command/_say,
Completion/Darwin/Command/_scselect,
Completion/Darwin/Command/_scutil,
Completion/Darwin/Command/_sw_vers,
Completion/Linux/Command/_chattr,
Completion/Linux/Command/_ldconfig,
Completion/Linux/Command/_lsattr,
Completion/Unix/Command/_attr: new completion functions for simple
utilities belonging to the 'Darwin' and 'Linux' groups.
* 42230: Completion/Unix/Command/_screen: update to 4.06.01
* 42229: Completion/Unix/Command/_awk, Completion/Unix/Command/_df,

View file

@ -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'

View file

@ -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

View file

@ -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'

View file

@ -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}})"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,6 @@
#compdef sw_vers
_arguments : \
'(-)-buildVersion[display build version only]' \
'(-)-productName[display product name only]' \
'(-)-productVersion[display product version only]'

View file

@ -0,0 +1,42 @@
#compdef chattr
local ret=1
local -a context line state state_descr
local -A opt_args val_args
_arguments -s -S : \
'-f[suppress most error messages]' \
"-p+[set file's project number]:project number" \
'-R[act recursively]' \
'-V[output verbosely]' \
"-v+[set file's version/generation number]:version/generation number" \
'1: :->attrs' \
'*: :_files' \
&& ret=0
[[ $state == attrs ]] &&
if compset -P '*[=+-]'; then
# These modes can't be changed with chattr: [EhINXZ]
_values -S '' attribute \
'A[no atime updates]' \
'a[append only]' \
'C[no copy on write]' \
'c[compressed]' \
'D[no synchronous directory updates]' \
'd[no dump]' \
'e[extent format]' \
'i[immutable]' \
'j[data journalling]' \
'P[project hierarchy]' \
'S[synchronous updates]' \
's[secure deletion]' \
'T[top of directory hierarchy]' \
't[no tail-merging]' \
'u[undeletable]' \
&& ret=0
else
compset -P '*'
_values -S '' operator = + - && ret=0
fi
return ret

View file

@ -0,0 +1,35 @@
#compdef ldconfig ldconfig.real
local ret=1
local -a context line state state_descr
local -A opt_args
_arguments -s -S : \
'(x -v --verbose)'{-v,--verbose}'[output verbosely]' \
'(x)*: :->files' \
+ x \
'(: -)'{-\?,--help}'[display help information]' \
'(: -)'{-p,--print-cache}'[display libraries in current cache]' \
'(: -)--usage[display brief usage information]' \
'(: -)'{-V,--version}'[display version information]' \
+ l \
'(x o)-l[manually link individual libraries (library mode)]' \
+ o \
'(x l -c --format)'{-c+,--format=}'[specify cache format]:cache format:(old new compat)' \
'(x l)-C+[specify cache file to use instead of /etc/ld.so.cache]:cache file:_files' \
'(x l)-f+[specify configuration file to use instead of /etc/ld.so.conf]:configuration file:_files' \
'(x l -i --ignore-aux-cache)'{-i,--ignore-aux-cache}'[ignore auxiliary cache file]' \
'(x l -N)-n[process only directories specified on command line (implies -N)]' \
'(x l)-N[do not rebuild cache]' \
'(x l)-r+[specify root directory]:root directory:_directories' \
'(x l)-X[do not update symbolic links]' \
&& ret=0
[[ $state == files ]] &&
if [[ -n ${opt_args[(I)l--l]} ]]; then
_object_files && ret=0
else
_directories && ret=0
fi
return ret

View file

@ -0,0 +1,11 @@
#compdef lsattr
_arguments -s -S : \
'-a[show all files, including hidden ones]' \
'-d[list directory entries instead of contents]' \
'-l[use long option names]' \
"-p[show file's project number]" \
'-R[act recursively]' \
'-V[display version information]' \
"-v[show file's version/generation number]" \
'*: :_files'

View file

@ -1,4 +1,4 @@
#compdef attr getfattr setfattr
#compdef attr getfattr setfattr xattr
case $service in
attr)
@ -45,4 +45,23 @@ case $service in
'*:file:_files'
return
;;
# The Python xattr module ships with a utility called xattr which might appear
# on some systems; it is not entirely compatible with the Darwin variant, but
# does seem inspired by it, to the degree that this is probably close enough
xattr)
_arguments -s -S -A '-*' : \
'(: -)'{-h,--help}'[display help information]' \
'(-c -d -w)-l[display in long format]' \
'-r[act recursively]' \
'-s[act on symbolic links]' \
'(-w)-v[always display file name]' \
'(-c -d)-x[use hexademical format for value input and output]' \
'*: :_files' \
+ '(op)' \
'(-l -x)-c[remove all attributes]' \
'(-l -x)-d[remove specified attribute]:attribute name' \
'-p[display value of specified attribute]:attribute name' \
'(-l -v)-w[set value of specified attribute]:attribute name: :attribute value'
return
;;
esac