diff options
Diffstat (limited to 'Completion/Darwin/Command')
-rw-r--r-- | Completion/Darwin/Command/_open | 8 | ||||
-rw-r--r-- | Completion/Darwin/Command/_otool | 7 | ||||
-rw-r--r-- | Completion/Darwin/Command/_shortcuts | 88 | ||||
-rw-r--r-- | Completion/Darwin/Command/_softwareupdate | 151 | ||||
-rw-r--r-- | Completion/Darwin/Command/_sw_vers | 7 | ||||
-rw-r--r-- | Completion/Darwin/Command/_system_profiler | 12 | ||||
-rw-r--r-- | Completion/Darwin/Command/_trash | 22 |
7 files changed, 204 insertions, 91 deletions
diff --git a/Completion/Darwin/Command/_open b/Completion/Darwin/Command/_open index 2563e5eb5..1c693dfb8 100644 --- a/Completion/Darwin/Command/_open +++ b/Completion/Darwin/Command/_open @@ -25,14 +25,20 @@ _open() { '(: * -)--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]' \ + '*--env[add the environment variable of the launched application]:env_var=value:_parameters -g "*export*" -qS=' \ '(-h)-f[open standard input with TextEdit or specified application]' \ '(-R)-F[open application with fresh state]' \ - '-g[do not bring application to foreground]' \ + '(-j)-g[do not bring application to foreground]' \ '(-f)-h[open library header file]' \ + '(-g)-j[launch the app hidden]' \ '(-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' \ + '--stdin[launch the application with stdin connected to the given file]:file:_files' \ + '--stdout[launch the application with stdout connected to the given file]:file:_files' \ + '--stderr[launch the application with stderr connected to the given file]:file:_files' \ '(-a -b -e -f -R -t)-t[open with default text editor]' \ + '-u[open URL with whatever application claims the url scheme]:url:_urls' \ '(-R)-W[wait for application to exit]' \ '(-f)*: :->files' \ && ret=0 diff --git a/Completion/Darwin/Command/_otool b/Completion/Darwin/Command/_otool index c3fc70b91..b6a30a730 100644 --- a/Completion/Darwin/Command/_otool +++ b/Completion/Darwin/Command/_otool @@ -13,6 +13,7 @@ _arguments \ '-D[display just the internal name of shared lib]' \ '-s[display the contents of the specified section]:segment name: :section name: ' \ '-t[display the contents of (__TEXT,__text) section]' \ + '-x[display the content of every __text section found in the file]' \ '-d[display the contents of (__DATA,__data) section]' \ '-o[display the contents of __OBJC segment]' \ '-r[display the relocation entries]' \ @@ -25,6 +26,9 @@ _arguments \ '-G[display the data in code table]' \ '-C[display the linker optimization hints]' \ '-P[print the info_plist section as strings]' \ + '-dyld_info[print bind and rebase information used by dyld]' \ + '-dyld_opcodes[print raw dyld bind and rebase opcodes present in a final linked binary]' \ + '-chained_fixups[print raw chained fixup data present in a final linked binary]' \ '-p[with -t and -v/V: start disassembly from the specified symbol]:symbol name: ' \ '-v[display verbosely (symbolically) when possible]' \ '-V[display disassembled operands symbolically]' \ @@ -34,7 +38,8 @@ _arguments \ '-function_offsets[with disassembly, print decimal offset from the last label]' \ '-j[with disassembly, print opcode bytes]' \ "-Q[use otool's disassembler]" \ - '-arch[select the specified architecture from a universal file]:arch:(i386 x86_64)' \ + '-addr_slide=[add an arbitrary slide to each pointer value when it is displayed]:slide size' \ + '-arch[select the specified architecture from a universal file]:arch:(i386 x86_64 x86_64h arm64 arm64e all)' \ '-m[object file names are not assumed to be in archive(member) syntax]' \ '(- *)--version[print version of otool]' \ '*:file:_object_files' && return 0 diff --git a/Completion/Darwin/Command/_shortcuts b/Completion/Darwin/Command/_shortcuts new file mode 100644 index 000000000..5e15f0a07 --- /dev/null +++ b/Completion/Darwin/Command/_shortcuts @@ -0,0 +1,88 @@ +#compdef shortcuts + +_shortcuts() { + local curcontext="$curcontext" + local -a line state + + _arguments -C \ + "1: :->subcommand" \ + "*:: :->args" + + case $state in + subcommand) + _values "subcommand" \ + "run[run a shortcut]" \ + "list[list your shortcuts]" \ + "view[view a shortcut in shortcuts]" \ + "sign[sign a shortcut file]" \ + "help[show subcommand help information]" + ;; + args) + case ${line[1]} in + run) + _shortcuts-run + ;; + list) + _shortcuts-list + ;; + view) + _shortcuts-view + ;; + sign) + _shortcuts-sign + ;; + help) + _shortcuts-help + ;; + esac + ;; + esac +} + +_shortcuts-run() { + _arguments \ + ":shortcut name or identifier:$(_shortcut_options)" \ + {-i,--input-path}'[specify input to provide to the shortcut]:input path:_files' \ + {-o,--output-path}'[specify where to write the shortcut output, if applicable]:output path:_files' \ + '--output-type[specify type to output data in]:output type (Universal Type Identifier format)' \ + {-h,--help}'[show help information]' +} + +_shortcuts-list() { + _arguments \ + {-f,--folder-name}"[specify folder name or identifier to list shortcuts in, or \"none\" to list shortcuts not in a folder]:folder name:$(_shortcut_folder_options)" \ + '--folders[list folders instead of shortcuts]' \ + '--show-identifiers[show identifiers with each result]' \ + {-h,--help}'[show help information]' +} + +_shortcuts-view() { + _arguments \ + ":shortcut name:$(_shortcut_options)" \ + {-h,--help}'[show help information]' +} + +_shortcuts-sign() { + _arguments \ + {-m,--mode}'[specify signing mode]:mode [people-who-know-me]:(anyone people-who-know-me)' \ + {-i,--input}'[specify shortcut file to sign]:input:_files -g "*.shortcut(-.)"' \ + {-o,--output}'[specify output path for the signed shortcut file]:output:_files -g "*.shortcut(-.)"' \ + {-h,--help}'[show help information]' +} + +_shortcuts-help() { + _arguments \ + ":subcommand:(run list view sign help)" +} + +# utilities + +_shortcut_options() { + echo "($(shortcuts list | sed 's/ /\\ /g'))" +} + +_shortcut_folder_options() { + echo "($(shortcuts list --folders | sed 's/ /\\ /g') none)" +} + +_shortcuts "$@" diff --git a/Completion/Darwin/Command/_softwareupdate b/Completion/Darwin/Command/_softwareupdate index 6054fd768..9ac9b9cd2 100644 --- a/Completion/Darwin/Command/_softwareupdate +++ b/Completion/Darwin/Command/_softwareupdate @@ -1,75 +1,110 @@ #compdef softwareupdate -_softwareupdate_ignored_update_name() { - if [[ -z "$_softwareupdate_ignored_updates" ]]; then - local res="$(_call_program pkgs softwareupdate --ignored)" - _softwareupdate_ignored_updates=("${(Qs/, /)${${res#Current ignored updates: \(}%\)}}") - fi - if (( ${#_softwareupdate_ignored_updates} > 0 )); then - _wanted pkgs expl "ignored package" compadd -a _softwareupdate_ignored_updates && return 0 - fi - return 1 +# rebuild cache for available updates everyday (ad hoc) +_softwareupdate_caching_policy() { + local -a newer=( "$1"(Nmd-1) ) + return $#newer } -_softwareupdate_update_name() { - local name line - if [[ -z "$_softwareupdate_updates" ]]; then +# completes available updates (with description) + +_softwareupdate_update_names () { + local name line update_policy ret=1 + local cache_id=softwareupdate-updates + zstyle -s ":completion:${curcontext}:" cache-policy update_policy + if [[ -z "$update_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy \ + _softwareupdate_caching_policy + fi + if { [[ ! -v _softwareupdate_updates ]] || _cache_invalid $cache_id } && + ! _retrieve_cache $cache_id; then + # Output format of 'softwareupdate --list' seems to be not stable, + # but at least on macOS 12 and 13 it contains the following two lines + # for each update: + #* Label: update name (may contain spaces) + # Title: description of the update (single TAB before Title:) + # softwareupdate(1) manpage says the '*' before the Label: is replaced + # by '-' for non-recommended updates (but I've never seen it). _softwareupdate_updates=() - for line in ${(f)"$(_call_program pkgs softwareupdate --list)"}; do - if [[ $line == ' '* ]]; then - name="${line# ? }" - elif [[ -n "$name" ]]; then - _softwareupdate_updates+=("$name:${line# }") - name="" + for line in ${(f)"$(_call_program updates softwareupdate --list)"}; do + if [[ $line = [-\*]\ Label:\ (#b)(*) ]]; then + # add '*' or '-' in front of the name; this will be removed later + name=$line[1]$match[1] + elif [[ -n $name && $line = $'\t'Title:\ (#b)(*) ]]; then + _softwareupdate_updates+=( $name:$match[1] ) + name= fi done + _store_cache $cache_id _softwareupdate_updates fi - if (( ${#_softwareupdate_updates} > 0 )); then - _describe -t pkgs "update name" _softwareupdate_updates && return 0 - fi - return 1 + # recommended and non-recommended updates + local rec=( ${${_softwareupdate_updates:#-*}#\*} ) + local non=( ${${(M)_softwareupdate_updates:#-*}#-} ) + _describe -t updates "update" rec && ret=0 + _describe -t non-recommended-updates "non-recommended update" non && ret=0 + return ret +} + +# completes versions of available macOS full installer (with description) + +_softwareupdate_installer_versions () { + local versions=() + for line in ${(f)"$(_call_program installer-versions + softwareupdate --list-full-installers 2>/dev/null)"}; do + if [[ $line = \*\ Title:\ *\ Version:\ (#b)([0-9.]##)* ]]; then + versions+=( ${match[1]}:${line#*Title: } ) + fi + done + _describe -t insteller-versions "version" versions } +# main completion script + _softwareupdate() { - local context state line expl - typeset -A opt_args + local -a specs - _arguments -R \ - '(-h --help -l --list)-q[quiet mode]' \ - {-l,--list}'[list all available updates]:*:' \ - {-d,--download}'[download to directory set in InternetConfig]:*:' \ - {-i,--install}'[install (requires root)]:*: :->install' \ - '--ignored[show or manage ignored updates list (per-user)]:*:: :->ignored' \ - '--schedule[scheduler preferences (per-user)]:automatic checking:(on off)' \ - {-h,--help}'[print command usage]:*:' && return 0 + if (( ${words[(I)(-i|--install)]} == 0 )); then + specs=( + '--no-scan[do not scan when listing or installing updates]' + '--product-types[limit a scan to a particular product type only]:list of product types' + '--products[a comma separated list of product keys to operate on]:list of product keys' + '--force[force an operation to complete]' + '--agree-to-license[agree to the software license agreement without user interaction]' + '--verbose[enable verbose output]' + '(* -)'{-h,--help}'[print command usage]:*:' - case "$state" in - install) - _arguments \ - '(* -a --all)'{-a,--all}'[all available active updates]' \ - '(* -r --req)'{-r,--req}'[all required active updates]' \ - '*:update name:_softwareupdate_update_name' && return 0 - ;; - ignored) - local -a ignored_subcmd - ignored_subcmd=(add remove) + + '(operation)' - if (( CURRENT == 1 )); then - _describe -t commands "subcommand" ignored_subcmd && return 0 - fi - case $words[1] in - add) - _softwareupdate_update_name && return 0 - ;; - remove) - _arguments \ - '(* -a --all)'{-a,--all}'[all available active updates]' \ - '*:update name:_softwareupdate_ignored_update_name' && return 0 - ;; - esac - ;; - esac - return 1 + {-l,--list}'[list all available updates]' + {-d,--download}'[download but not install specified updates]:*: : _softwareupdate_update_names' + {-i,--install}'[download and install specified updates]' + '(* -)--list-full-installers[list the available macOS installers]' + '(* -)--fetch-full-installer[install the latest recommended macOS installer]: :(--full-installer-version): : _softwareupdate_installer_versions' + '--install-rosetta[install Rosetta 2 (Apple Silicon only)]' + '(* -)--schedule[returns the per-machine automatic check preference]' + '--background[trigger a background scan and update operation]' + '(* -)--dump-state[log the internal state of the SU daemon to /var/log/install.log]' + '--evaluate-products[evaluate a list of product keys specified by the --products option]' + '--history[show the install history]' + ) + else # if -i/--install is already on the command line + specs=( + !{-i,--install} + '(-R --restart)'{-R,--restart}'[automatically restart if required to complete installation]' + '--stdinpass[password to authenticate as an owner (Apple Silicon only)]' + '--user[local username to authenticate as an owner (Apple Silicon only)]' + '*: : _softwareupdate_update_names' + + + '(select-updates)' + + '(*)'{-a,--all}'[all updates that are applicable to your system]' + '(*)'{-r,--recommended}'[all updates recommended for your system]' + '(*)--os-only[only macOS updates]' + '(*)--safari-only[only Safari updates]' + ) + fi + + _arguments -s : $specs } _softwareupdate "$@" diff --git a/Completion/Darwin/Command/_sw_vers b/Completion/Darwin/Command/_sw_vers index 11814e0b0..415d3a05c 100644 --- a/Completion/Darwin/Command/_sw_vers +++ b/Completion/Darwin/Command/_sw_vers @@ -1,6 +1,11 @@ #compdef sw_vers +# Only options with a single dash '-' are accepted on Monterey or older, +# but both a single and double dashes are accepted on Ventura (or newer). +# We may replace '-' by '--' when Monterey fades out. + _arguments : \ '(-)-buildVersion[display build version only]' \ '(-)-productName[display product name only]' \ - '(-)-productVersion[display product version only]' + '(-)-productVersion[display product version only]' \ + '(-)-productVersionExtra[display rapid security response version only]' diff --git a/Completion/Darwin/Command/_system_profiler b/Completion/Darwin/Command/_system_profiler index fe197579d..0fd8b473b 100644 --- a/Completion/Darwin/Command/_system_profiler +++ b/Completion/Darwin/Command/_system_profiler @@ -4,17 +4,13 @@ typeset -A opt_args local context state state_descr line local -a _data_types -# TODO: Should this be static? Calling `system_profiler -listDataTypes` takes -# about 0.07-0.08 secs on my machine. Does this list ever change (between -# different versions of OS X)? -_data_types=( SP{AirPort,Applications,Audio,Bluetooth,Camera,CardReader,Component,ConfigurationProfile,DeveloperTools,Diagnostics,DisabledSoftware,DiscBurning,Displays,Ethernet,Extensions,FibreChannel,FireWire,Firewall,Fonts,Frameworks,Hardware,HardwareRAID,InstallHistory,Logs,ManagedClient,Memory,Network,NetworkLocation,NetworkVolume,PCI,ParallelATA,ParallelSCSI,Power,PrefPane,Printers,PrintersSoftware,SAS,SPI,SerialATA,Software,StartupItem,Storage,SyncServices,Thunderbolt,USB,UniversalAccess,WWAN}DataType ) -# the dynamic alternative is: -#_data_types=( ${${(f)"$(_call_program path system_profiler -listDataTypes 2>/dev/null)"}[2,-1]} ) +_data_types=( ${${(f)"$(_call_program data-types system_profiler -listDataTypes 2>/dev/null)"}[2,-1]} ) _arguments \ '(- *)-usage' \ '(- *)-listDataTypes[lists the available datatypes]' \ - '(-listDataTypes -usage)-xml[generate xml output]' \ + '(-listDataTypes -usage -json)-xml[generate xml output]' \ + '(-listDataTypes -usage -xml)-json[generate json output]' \ '(-listDataTypes -usage)-detailLevel[level of detail for the report]:detail level:(mini basic full)' \ - '(-listDataTypes -usage)-timeout+[maximum time to wait in seconds]' \ + '(-listDataTypes -usage)-timeout+[maximum time to wait in seconds(0 means no timeout)]:timeout seconds' \ '(-listDataTypes -usage)*:data type:'"($_data_types)" diff --git a/Completion/Darwin/Command/_trash b/Completion/Darwin/Command/_trash deleted file mode 100644 index 658716432..000000000 --- a/Completion/Darwin/Command/_trash +++ /dev/null @@ -1,22 +0,0 @@ -#compdef trash - -# We only provide completion for Ali Rantakari's trash utility. There are/were a -# few others floating around with that name, but this is the one available as -# `trash` in Homebrew and MacPorts -_pick_variant ali='(Rantakari|hasseg)' other --version && { - # The hidden options here are options to rm that trash silently (and - # undocumentedly) ignores. Some options are not made mutually exclusive where - # they technically could be, for compatibility with aliases, etc. - _arguments -s -S -A '-*' : \ - '!-'{d,f,i,r,P,R,W} \ - '(: * -F -l -v)-e[empty trash]' \ - '-F[use Finder instead of system API]' \ - '(: * -e -F -s -y)-l[list items in trash]' \ - '(: * -F -l -v)-s[securely empty trash]' \ - '-v[increase output verbosity]' \ - '-y[skip confirmation prompts (with -e or -s)]' \ - '*: :_files' - return -} - -_default |