From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4337 invoked from network); 3 Jul 2023 16:31:47 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 3 Jul 2023 16:31:47 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1688401907; b=l4irpzz8Sw2Kns4PoUGHMSCUAh2Gu8B8zCnKgFtRXSjcC7vQDWFpVAS0FTGXPYfrAn9y6IYAyF 94G0cfclLss2aJ8L+8U91Ey4QNrng0+03t05ZNI/X9FQnQ4QnPtRuwyawUXsStLCBaeXjXtGuW nDmEmzaIv19BivLsRNllCs12Ny1TfKrHx3ynkBYAelGX9UnNLwK/zxf/EeCcTj7jZD57hKyanB wHRvwleV3QNQJxwcvVJLtA4NurjmXRHD9CNkA7vm2C6R1zxGjG0SN4uHJYueN7qYmlRsShL4BV 1WSalmzphnWESwqdV3s3uOqulkg9Ay2EBLzZQgSTvENrzA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (snd00005-bg.im.kddi.ne.jp) smtp.remote-ip=27.86.113.5; dmarc=none header.from=kba.biglobe.ne.jp; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1688401907; bh=TbwCBQbGP4WTza7E13UZCiyRQxOSxVMCUPT9BqeY/jk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Message-ID:In-Reply-To:To:References:Date:Subject: MIME-Version:Content-Transfer-Encoding:Content-Type:From:DKIM-Signature; b=IKogeqlo8F0Cy946Gdgbk05py/tewWR8KqEE6Krz/3Fm9hzc0KIE6IpWYfyrUjgAWT7thqOMdd dCGR7BBl0LjWUTCLqne/gUJZnGvAx45mP+8eRpBPW/9GHJALO6wn9O4l4sZ4u++FqcjLAm1eL4 vhJuIEve+uAf8e1IfrKQ1ECTZvSIcTjH6hANc+JwY8X/9qKYD/CLA51euspMpwHNROjQzTPMzg wi09kfCoIasuXHolFzKLW88mbqDF7tHQt7FcEzkGevgtY/fCSolecrgjONU2pYE6Og0Kr5hWg5 d79KDts+3gf9HNkoHp1eioKxpxuqJ5lZgOhyziRKTshwTw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-Id:In-Reply-To:To:References: Date:Subject:Mime-Version:Content-Transfer-Encoding:Content-Type:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ceR7jmGWFWT5n3iJv50cD8r7ZLLMNPBYs+kaBx6AiYU=; b=lBHeo4Az3AJnGKt7LXlRrgf+z/ JShoov5lUojmTn2eqMxdDz8cTbAv4hqhvoxsmk2qvu76exdUKXxPFuZ/BDYK2TOJ908ljePrQKews +k3z+ufqGHAxQyRH0GenBDTmhFMCuxWAuFwOyAV/FPSSXzo/ZWp3tVbXhHr9ukJyYeKpYmQ373V50 mRV6PTnkCiXoZhQojmYhjrNJeOz2mx4LuFmP+oEZAIE64+8HcLwtvq94XROPkZUscSvWTn3fJLf7b M9tg89KAmHtIqAnV7qSDSILRPzetDUB/7/fcn2GKjnSep0Z5TgskosxgN3Msy1Oe4QZSr7rWJ8ywO XktIdcdg==; Received: by zero.zsh.org with local id 1qGMSo-000M6n-49; Mon, 03 Jul 2023 16:31:46 +0000 Authentication-Results: zsh.org; iprev=pass (snd00005-bg.im.kddi.ne.jp) smtp.remote-ip=27.86.113.5; dmarc=none header.from=kba.biglobe.ne.jp; arc=none Received: from snd00005-bg.im.kddi.ne.jp ([27.86.113.5]:35296 helo=dfmta0014.biglobe.ne.jp) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1qGMSS-000LpR-Kx; Mon, 03 Jul 2023 16:31:27 +0000 Received: from mail.biglobe.ne.jp by omta0014.biglobe.ne.jp with ESMTP id <20230703163117978.QPFB.128058.mail.biglobe.ne.jp@biglobe.ne.jp> for ; Tue, 4 Jul 2023 01:31:17 +0900 From: "Jun. T" Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.3\)) Subject: Re: [PATCH 1/1] Update softwareupdate completion for macOS 13 Date: Tue, 4 Jul 2023 01:31:16 +0900 References: <20230628094734.130645-1-syohex@gmail.com> <20230628094734.130645-2-syohex@gmail.com> To: zsh-workers@zsh.org In-Reply-To: <20230628094734.130645-2-syohex@gmail.com> Message-Id: <61EBD1E7-B849-4A5F-A613-A908E103CD6E@kba.biglobe.ne.jp> X-Mailer: Apple Mail (2.3696.120.41.1.3) X-Biglobe-Sender: takimoto-j@kba.biglobe.ne.jp X-Seq: 51897 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Thank you for the update. I've never used softwareupdate, but it seems _softwareupdate needs some more updates. (1) The output format of 'softwareupdate --list' has changed and the current _softwareupdate_ignored_update_name() doesn't work. (this is rather hard to test since 'softwareupdate --list' gives nothing if your Mac is fully updated) (2) --download requires one or more update names. The patch below (against the current master) also includes: (3) use '+ (option_group)' for mutually exclusive options. (4) complete version numbers of available macOS full installers. (5) some simplifications (do not call _arguments multiple times, etc.) diff --git a/Completion/Darwin/Command/_softwareupdate = b/Completion/Darwin/Command/_softwareupdate index 6054fd768..e4bdede86 100644 --- a/Completion/Darwin/Command/_softwareupdate +++ b/Completion/Darwin/Command/_softwareupdate @@ -1,75 +1,105 @@ #compdef softwareupdate =20 -_softwareupdate_ignored_update_name() { - if [[ -z "$_softwareupdate_ignored_updates" ]]; then - local res=3D"$(_call_program pkgs softwareupdate --ignored)" - _softwareupdate_ignored_updates=3D("${(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=3D( "$1"(Nmd-1) ) + return $#newer } =20 -_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=3D1 + local cache_id=3Dsoftwareupdate-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=3D() - for line in ${(f)"$(_call_program pkgs softwareupdate --list)"}; do - if [[ $line =3D=3D ' '* ]]; then - name=3D"${line# ? }" - elif [[ -n "$name" ]]; then - _softwareupdate_updates+=3D("$name:${line# }") - name=3D"" + for line in ${(f)"$(_call_program updates softwareupdate --list)"}; = do + if [[ $line =3D [-\*]\ Label:\ (#b)(*) ]]; then + # add '*' or '-' in front of the name; this will be removed = later + name=3D$line[1]$match[1] + elif [[ -n $name && $line =3D $'\t'Title:\ (#b)(*) ]]; then + _softwareupdate_updates+=3D( $name:$match[1] ) + name=3D 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=3D( ${${_softwareupdate_updates:#-*}#\*} ) + local non=3D( ${${(M)_softwareupdate_updates:#-*}#-} ) + _describe -t updates "update" rec && ret=3D0 + _describe -t non-recommended-updates "non-recommended update" non && = ret=3D0 + return ret } =20 -_softwareupdate() { - local context state line expl - typeset -A opt_args +# completes versions of available macOS full installer (with = description) =20 - _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 +_softwareupdate_installer_versions () { + local versions=3D() + for line in ${(f)"$(_call_program installer-versions + softwareupdate --list-full-installers)"}; do + if [[ $line =3D \*\ Title:\ *\ Version:\ (#b)([0-9.]##)* ]]; then + versions+=3D( ${match[1]}:${line#*Title: } ) + fi + done + _describe -t insteller-versions "version" versions +} =20 - 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=3D(add remove) +# main completion script +local -a specs =20 - if (( CURRENT =3D=3D 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 -} +if (( ${words[(I)(-i|--install)]} =3D=3D 0 )); then + specs=3D( + '--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]:*:' + + + '(operation)' + + {-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=3D( + !{-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 that are recommended for your = system]' + '(*)--os-only[only macOS updates]' + '(*)--safari-only[only Safari updates]' + ) +fi =20 -_softwareupdate "$@" +_arguments -s : $specs