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=-0.4 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,RDNS_NONE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: from authenticated user by zero.zsh.org with local id 1kiNfK-0006IB-6I; Thu, 26 Nov 2020 20:14:54 +0000 Authentication-Results: zsh.org; iprev=pass (relay10.mail.gandi.net) smtp.remote-ip=217.70.178.230; dmarc=none header.from=chazelas.org; arc=none Received: from relay10.mail.gandi.net ([217.70.178.230]:40693) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1kiNez-00063h-GK; Thu, 26 Nov 2020 20:14:34 +0000 Received: from chazelas.org (unknown [94.10.124.211]) (Authenticated sender: stephane@chazelas.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 353EF240002; Thu, 26 Nov 2020 20:14:31 +0000 (UTC) Date: Thu, 26 Nov 2020 20:14:31 +0000 From: Stephane Chazelas To: Oliver Kiddle Cc: Zsh hackers list Subject: [PATCH] ulimit option completions using ulimit -a output Message-ID: <20201126201431.a6ym56gcagomyvzk@chazelas.org> Mail-Followup-To: Oliver Kiddle , Zsh hackers list References: <20201123214942.hi2rx7n3jk25ucmd@chazelas.org> <74327-1606347813.918593@HxCz.NV4p.AwzH> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <74327-1606347813.918593@HxCz.NV4p.AwzH> X-Seq: 47642 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: Archived-At: 2020-11-26 00:43:33 +0100, Oliver Kiddle: [...] > > * 1. Add zsh_LIMIT_PRESENT(RLIMIT_XXX) in configure.ac. > > * 2. Add an entry for RLIMIT_XXX to known_resources[]. > > * Make sure the option letter (resinto_T.opt) is unique. > > - * 3. Build zsh and run the test B12rlimit.ztst. > > + * 3. Add entry in documentation for the limit and ulimit builtins > > + * 4. Build zsh and run the test B12rlimit.ztst. > > 5. Update Completion/Zsh/Command/_ulimit > > Units were often fairly well documented there but are missing in a > couple of cases so you may be able to add a couple. [...] The problem is that the list of ulimit options is system dependent, so I propose the improvement below which uses the output of ulimit -a to build the list of completions. From: Stephane Chazelas Date: Thu, 26 Nov 2020 19:22:03 +0000 Subject: [PATCH] ulimit option completions using ulimit -a output The list of options supported by ulimit is system dependent. Rather than hardcoding the full list of options supported on any system in the completer, we get the list of options from the output of "ulimit -a". That means less descriptive descriptions but more relevant completions to the user (and not having to update the completer every time a new limit is added). --- Completion/Zsh/Command/_ulimit | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Completion/Zsh/Command/_ulimit b/Completion/Zsh/Command/_ulimit index 0526821dd..06bcfc34c 100644 --- a/Completion/Zsh/Command/_ulimit +++ b/Completion/Zsh/Command/_ulimit @@ -2,18 +2,16 @@ [[ $PREFIX = u* ]] && compadd unlimited && return 0 +local -a opts +setopt localoptions extendedglob + +opts=( + ${${${(fo)"$(ulimit -a)"}:#-N*}%% *} +) _arguments -s \ '-H[set hard limits]' \ '-S[set soft and hard limits (with -H)]' \ - '(-H -S -c -d -f -l -m -n -s -t *)-a[list all current resource limits]' \ - '-c[core dump size limit]:max core dump size (512-byte blocks)' \ - '-d[maximum size of data segment]:maximum size of data segment (K-bytes)' \ - '-f[size of largest file allowed]:size of largest file allowed (512-byte blocks)' \ - '-l[maximum size of locked in memory]:maximum size of locked in memory (K-bytes)' \ - '-m[maximum size of physical memory]:maximum size of physical memory (K-bytes)' \ - '-n[maximum no. of open file descriptors]:maximum no. of open file descriptors' \ - '-s[stack size limit]:stack size limit (K-bytes)' \ - '-t[maximum cpu time per process]:maximum cpu time per process (seconds)' \ - '-u[processes available to the user]:processes' \ - '-v[maximum size of virtual memory]:maximum size of virtual memory (K-bytes)' \ - '*:size of largest file allowed' + '-N+[specify limit by number]:limit number' \ + "(-N ${(M@j: :)opts#-?} *)-a[list all current resource limits]" \ + ${opts/(#b)(-?): (*)/$match[1][$match[2]]:$match[2]} \ + '*:file size (blocks)' -- 2.25.1