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 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 576 invoked from network); 21 Mar 2023 01:06:11 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 Mar 2023 01:06:11 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1679360771; b=Be7QNulOdhAGpS/G9bVq3lA86aqdHm/7ICRXtzj5Npt5aai+AwQSiKAIolXGu+ekAJ8O05pJh9 DKU3IAzJYmspxw/bN8M7KWL9gu3K97sgMQy45D3fRxrilCAxw8Sk9wUVvS1pVg+nvHMWS8AkZZ WLJ8SVkfLTryvLt8m8psexkIH67I3c9E/f8BdyF1b99kvR6frChRNsK29XLv6v/jeM1sREH+u6 g0+mwsVQDi+741tqLgvvcjUMTQMYh5zF0Rp0lrAmK5rO1q8gojqL6j0ICCSCnADwNe5vTflo4u RvF4wf1S109pdZ8cme2r4ssOkc/M56+23IHQLJicY+3PXw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f48.google.com) smtp.remote-ip=209.85.208.48; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1679360771; bh=CuaWMjA0LBIaFoXKiIfXjw1AOVzgC/LlPIHvdwHfDkw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=cwm54AAmfha6zPtrXF4w/3V5GpImlo+LmrF/BNLYIwe847S/rMCJGLxypPIpqnwIM9cE/DbvfO 5jStYH3q9BfSC6Yon+py/8jhu9hxEmmq8wDk8DXYiQ5f73zTln8Jqf5SSdct3Ju3qvj7LO6UZ3 9A5q/umejLS8BHkgtD08SXbFFBp3AxVQ7tpU4JaHcgn0WwnrRGPHZVWZ7FPCux778IeicQh68n zQ5XyPA9RNegOAqL4yQQm49S4aInNBLyxvoF3M6zs599qKl3SEjZxJy8ENLSWTVEHLG6Ri6Ard iBaw/1PJD5wyFcbnRUf5yzlmrAbtLMIfqIjZBm9bgsPv3g==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=1CB923Wa6ulQ9AihhBHL7a6BqCYMisUyRoxbOgY39mI=; b=PuOrZWg9leDclTQMtThClrjbyQ GVEMXbs48t4R9x2gYfL6yKGWY49bsU/yyKmzR9218xPiNutVuPfnBGcuJ9lz2MQzRN5pTUJJXM5vF CXpNSTunSnDpCwaAsiApXJmoF+Z6cL/ywSWZqytdXhuGk5XcoU6PqhbCTGrSzy7YC/7PNh4P9cyis KBP9BDMINI5zD6f+efI72guBNvc8K/OKbqVgQn/QphXoeEvj2iTmvB0xYzvoiD/bFcVW8iprcgsS2 8fkMcbHxiQzJbelCOI0pVWnkmg5ihpmj9/6fP6sYPeDZbYe/NGB6COiMi0AEPuywiaViKiaBQia5X NWEPawZA==; Received: by zero.zsh.org with local id 1peQS1-00051g-Go; Tue, 21 Mar 2023 01:06:09 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f48.google.com) smtp.remote-ip=209.85.208.48; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f48.google.com ([209.85.208.48]:34553) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1peQRl-0004ik-OA; Tue, 21 Mar 2023 01:05:54 +0000 Received: by mail-ed1-f48.google.com with SMTP id b20so20861758edd.1 for ; Mon, 20 Mar 2023 18:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; t=1679360753; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1CB923Wa6ulQ9AihhBHL7a6BqCYMisUyRoxbOgY39mI=; b=MKFo+jj64bUTmKPRwVyRYayZyNtPiTJVLOumyWtTTQpiIhQRdnt4MFZTw7DngFo6HZ urfMDwtwrsnCJWRFNfPkozUAWGawdK4YeJvJueXIVBbHbEflv6fIDVL0B8Jot+Gj8Z56 uFBm5Z5jR1/Qd4SlrXCzdZptfP1/M0H5JIRWp3pjr+cAIi6BWJcCohY6CcDf420Sn7ys FdNNUJ/6e8JtLvOo5V40rkAInjHtV1mNxvZEtjnL1M/XaMhnuQD62ZFwje+UptiHHMmC 3i8PV6t4OHqn4JjwL4gaSXnuyrtON0mXfBbDtqWtcZfq6JL5BGY1jPr1tG6i2GLJ1Vi7 l8ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679360753; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1CB923Wa6ulQ9AihhBHL7a6BqCYMisUyRoxbOgY39mI=; b=DNmRShU178Ljjyg9qKc14HZn9P9wnMN3dLkugojt0xJj+ak8TlsrncsdcrL1l02GiV 93wAKLNhffwhvKRERT278HWfwr7yq8iY6n/uwYv5x7gggAoKbP77+uNRloI/y8k9qQWB ow5SCl6PD90QOylnnjw8cHhTrNlvREFAEUvx84H14hqEI8HMN6IY2855uy6pROZT/Qsb GnyWU7yvQcRjZYG78Gspe8ifgMoApjvhNZDH5HxAm4gqiP0DfcrDVO9z1JczVxuNoJ1p WCPBri1W4W2lO6f2frdFwmupTSAzPz+v2VakrVTMLy1+TcDVZ938TCdwxmA+oU3oG3mg 55VA== X-Gm-Message-State: AO0yUKVBbBx8fiKb3OuOKSVvi+BgivtBLG28fKoBnO0JPnD0Zx+8R1By P1KjjWV/yons7ZKP4IyDCKr7pdHE4UXRCGk+xn48VQ== X-Google-Smtp-Source: AK7set/2kemPZGpGfgYm7FgyGfpfwbubQ7A0sVd4WpQoQaJVX02zgysAX3wUhD5aOGVkffVQ4f4UjEl2Crvk9twL69g= X-Received: by 2002:a17:906:9493:b0:930:5518:be77 with SMTP id t19-20020a170906949300b009305518be77mr423799ejx.12.1679360753099; Mon, 20 Mar 2023 18:05:53 -0700 (PDT) MIME-Version: 1.0 References: <1454747193.3405418.1678210315384@mail.virginmedia.com> In-Reply-To: From: Bart Schaefer Date: Mon, 20 Mar 2023 18:05:41 -0700 Message-ID: Subject: Re: How to fix run-help-* functions? To: Michele Venturi Cc: Mikael Magnusson , zsh-workers@zsh.org Content-Type: multipart/mixed; boundary="0000000000002394a605f75ea5d4" X-Seq: 51593 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: --0000000000002394a605f75ea5d4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 20, 2023 at 7:37=E2=80=AFAM Michele Venturi = wrote: > > I hope that's enough context Typically we'd like at least OS, zsh version, whether you built it yourself or installed packaged binaries, and a copy-paste of text from your terminal showing the command you ran and the resulting output (edited to relevant portions if very long). Also "functions -T run-help" (in this case) would produce xtrace output of the function, which might help you investigate before asking others to do so for you. However, given we're already this far down a thread: > I've an alias named "pkgu" set to "sudo pacman -S -y -u" and "run-help pk= gu" gives > the same error as before, can you check it on your end? Besides not anticipating use outside widget context, some recent changes to run-help also did not consider that aliases result in a recursive call, or (at least) presumed that aliases would always mention their own name somewhere in the expansion (e.g., alias foo=3D"sudo foo" or the like). Same symptom, somewhat different cause. Both stem from an attempt to optimize out a while-loop by using ${ary[(i)...]} which in turn didn't consider what happens when the (i) search fails. However, we're approaching a point of diminishing returns here. Further attempts to make sense of the foregoing risk e.g. regressing workers/31634. It may be better to discard the error output from the failed shift and get on with things. After some memory-refreshment with the mailing list archives of past changes, the problem comes down to something like this: Suppose we have an alias like g=3D'git' and on the command line is "g diff". We'd like the run-help widget to first unpack "g" and then analyze the full command line as "git diff" which ultimately invokes "run-help-git diff" to finally produce the help for the git "diff" subcommand. So in widget context, run-help starts by looking up "g" as an alias and makes a recursive call on "run-help git" -- which isn't good enough, it's lost the argument "diff". This is where getln/print -z come in, the recursive call pulls up the original command line (getln), discards the "g", and appends the remainder to get "git diff" and off we go. However, there are all sorts of complications -- what if the alias is g=3D'LANG=3DC sudo git' or some such? Skipping arbitrary prefix stuff to reach the "remainder" is what that "shift" is attempting to do. When run-help is invoked outside widget context, there's no source line to search for the original command name. My first pass at this fell back on searching the arguments passed to run-help, but that fails on the recursive call into the expansion of the alias because the "original command" doesn't actually appear in the expansion. It's possible this would also fail in widget context if one alias itself expanded to a second alias, etc. And that doesn't even begin to get into possible side-effects of "alias -g". There are several other ways this can fail -- so the most reasonable thing might be to give up if "skip the prefix" fails and treat the command as too complex to generate help. The attached (follows on to previous patch) might do a little better than simply "give up", but it also might introduce some unwanted differences. --0000000000002394a605f75ea5d4 Content-Type: text/plain; charset="US-ASCII"; name="rh_shift.txt" Content-Disposition: attachment; filename="rh_shift.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_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vbW1hbmQgaXRzZWxmICYgZXZlcnl0aGluZyBiZWZvcmUgaXQuCi0gICAgICAgICAg ICAgICAgc2hpZnQgJGNtZF9hcmdzWyhpKSR7cnVuX2hlbHBfb3JpZ19jbWQ6LSQxfV0gY21kX2Fy Z3MgfHwKKyAgICAgICAgICAgICAgICBzaGlmdCAkY21kX2FyZ3NbKGkpKCR7cnVuX2hlbHBfb3Jp Z19jbWR9fCQxKV0gY21kX2FyZ3MgMj4vZGV2L251bGwgfHwKICAgICAgICAgICAgICAgICAgICAg Y29udGludWUKIAogICAgICAgICAgICAgICAgICMgRGlzY2FyZCBvcHRpb25zLCBwYXJhbWV0ZXIg YXNzaWdubWVudHMgJiBwYXRocy4K --0000000000002394a605f75ea5d4--