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 1938 invoked from network); 15 Apr 2023 19:48:29 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Apr 2023 19:48:29 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1681588109; b=n8+0yod/hWHJw9z8uyP5WX4vEM8M+fi1oUaHDBSZPw8o/VghxP0DiVd7aZOzfutOcP9a6ywpA+ X0rinQ6A3xZj1ubGekTDXtjBYBTNvIroJ4wET11yDpoXUy8ZiDrBPq2kR8Xqx/mmjPbj4ictJU +kaBysO3GvNvm7zbyUor9Ag5ry+5yzQzkifuHtD74wj5GANzM1uWcRhyeeEgcfh1uMcvd4UGTw xt4oIR4sbP6gV9EXbhBRwNA8C2V0Ej/XmI0hzUI+SdGHWdB9ThElxs3oKpxTIiMyp6sxij52bC PUQn6Zo1R/1vWjwxSKBYbw+2Zmh0LW0ARAYwsR6aa7lZxQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f42.google.com) smtp.remote-ip=209.85.218.42; dkim=pass header.d=brasslantern-com.20221208.gappssmtp.com header.s=20221208 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=1681588109; bh=noctamafqRSU3USEP1ya4C6apH8Ge9N3BhzKw+znKg8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=bawTVadkyEX5kCiQcQnQ0SGOKzkJukMsdUZ/qUGkk6yV9jFe9EeWJ+tHwrA86oVzbUOGv4ZaBN OkO4z4k0A7OpBQjEJ6LEdnAGbN3H2+0u7gLahReoYrYuLjTVO8V9kdn05KOgIeKO88oVmDYnxd s1i18Mw8wyQGDjXDUtSVPuwFSGnWHXTOQxlc3yHbMkwfWUqg1kQ0ci0LoiAmUcU9FJMhneGELc Hb7NMbRvtZKVkcGUH+Ca8ua1QVEdOPUNTGad+hZAtFSi36AFG84d4TyPg9lTx7XUGjoJGhcOaQ rhr9Xui/spwCoI5whXbN0vDOPpkeAyVGCfG6BM5wUI1Xuw==; 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-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=BVZDsnjXpQDg6nLQaeBMBS3WP6xxR0+akFK9ZVrhSo4=; b=RnfTrTDA6iFMRKRKEorYcwgZ6e LCzw9lb8z1A+vdjwczpvOKY+h455dhHEGoVooDe7x1rBKH4cJGBTyFiG2GsOj6idkz5m+Pj9m0Pdh ++O9ehnkH+h2rtGwdxEzbnVKWBvGlobWVJeylqT+lcQTMeKYUcyZYoRQJKndvSlLxmfXMEFNCThga v9HUZcmd2kKM3yMdPZsADteFGMvp8xKnkANNNrsWvFq077YbvL/CqZTls8AiMzKgIdJMxieF/n7cj AfVC40PDsonwDQ0Cg4k5rVuNtMfX3Vr7TJi1aVPRdBInmJUjh+oNynDB11BJcXZ/ESuv1Hqubxgse P0bJdi3g==; Received: by zero.zsh.org with local id 1pnlsq-000JR7-4b; Sat, 15 Apr 2023 19:48:28 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f42.google.com) smtp.remote-ip=209.85.218.42; dkim=pass header.d=brasslantern-com.20221208.gappssmtp.com header.s=20221208 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f42.google.com ([209.85.218.42]:45822) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pnlsD-000Iky-PV; Sat, 15 Apr 2023 19:47:50 +0000 Received: by mail-ej1-f42.google.com with SMTP id u3so2105281ejj.12 for ; Sat, 15 Apr 2023 12:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20221208.gappssmtp.com; s=20221208; t=1681588069; x=1684180069; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BVZDsnjXpQDg6nLQaeBMBS3WP6xxR0+akFK9ZVrhSo4=; b=mRlWsPzX7azfHILQvWFWVi7+F8BC/HL2e2LyOuDdnfFUgKPMHgYf3OIsnRFk3srMw4 V7INzugl2E7gT0t7eckXa7LoILMffrEd4c0LaEEGbcLW+jTnsKqmNEutlrORcMAM5i3b IrnSb1aFlviKQtV+C80oOO5CDiyWh/VOpPn1/GYgwQ6O/WvTehXxHKQy1CzIWn89fAP/ HqhRykRYYA6Ptw0QPUqA2zx3yTVg/dZhlJ0P5QW6kuuNCvcz456qnS504RsFbX/XmvoM UGhwI46TyDcIsoTNLGYymzFKYxLx9k9+TgRAd2ISg1+ePSL9Qq276dF4WsqouPApBYdR T9zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681588069; x=1684180069; h=content-transfer-encoding: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=BVZDsnjXpQDg6nLQaeBMBS3WP6xxR0+akFK9ZVrhSo4=; b=MBq7QYRRheaiqIWEakT3u4I4fn9UPVqfCN3JTEGEZr2spPKW7pvHgd/3rpCpA705Yt b6YlFwW4j+O7tpXXcg6CA4pyyUQar/SiHgJvjl7cjd3YpbsqUtyyRdy44aQxfkiSqm1p W0KlVjgxqUCrPbLGKoSSlpd8dXwFqCLB4I2oNgzuM0sm9QBmVum9RPO6DYbFUAL4b7zX rsL7atTmPMSsQpIXQ7cohrha6NLlX9F2tDzQHxcbnPo74uazUrwwCiYjjn4OuwEm8nhs jVrIIc7JU+b9YtiU6wkLfX5nB/Z3g9s1nMv3XsJBiUaBsb9tEv8E+7ud2QP8B6w80ceK QbVw== X-Gm-Message-State: AAQBX9e6dDeSqBsDSZJJZGejTMFh7fGqYpc0sX4i1n2NF5TOgRKE91Ha Osb43iB4jIT00kM5NjSTJGpm7ZeRCOhbgkPOLS28AA== X-Google-Smtp-Source: AKy350YipFkG0D3osYzAIAOpQslYu2gJnm55POacdGhHkpRUmU+gTs/MlqFquNhJwCeR7aStsYMG1fs59dOkNh+joEw= X-Received: by 2002:a17:906:71c5:b0:947:5acb:920c with SMTP id i5-20020a17090671c500b009475acb920cmr3307368ejk.34.1681588068958; Sat, 15 Apr 2023 12:47:48 -0700 (PDT) MIME-Version: 1.0 References: <81609CF4-42DA-4E0F-A6E5-C5D58578B4F7@easesoftware.com> <9a1f77ea-ee4e-95ff-a571-5cd3ddce6cb2@eastlink.ca> In-Reply-To: From: Bart Schaefer Date: Sat, 15 Apr 2023 12:47:37 -0700 Message-ID: Subject: "Pull just the text of a single command" (was Re: .zsh_history) To: Ray Andrews Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29025 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Sat, Apr 15, 2023 at 8:30=E2=80=AFAM Ray Andrews wrote: > > I'm 100% certain you can do that, but not with history expansion, you'll > > need to use zle for that. > I'd sure like to know how! Back in the day nobody seemed to know how to > do it, not even Bart. I'm not sure which past discussion you're referencing, but it's possible you're mixing your metaphors here. "History expansion" is what happens when you use !! or !-2 or similar references at the prompt. That happens before pretty much anything else as soon as you hit enter (or even sooner if you have setopt magic-space or similar). In this case you can use !# to refer backwards to any words already entered: % echo first !#:1 last !#:3 first first last last % echo everything so far !# and more everything so far echo everything so far and more References to the stored history with "fc" and related commands like "history" accesses events (don't think in terms of "lines" -- a multi-line command like if/while/for is usually one event) that have previously been executed. This doesn't have access to the event currently being executed, and those events are stored with history expansions (like !# in the foregoing, etc.) already replaced. ZLE has access to what you're entering as you are entering it and before either of the above things (or any other expansions like globbing etc.) happen. So if you want the unaltered text as you work with it, ZLE is where you get it. The best place to grab it after hitting enter is probably in the zle-line-finish hook, but that won't always give you full multi-line events (e.g., when the PS2 prompt is active, you get it a line at a time). Finally, the preexec function (and hook) gives access to the full event with only history expansions already done (in $1), before it is entered into the "fc"-able history, along with the event with all the other expansions done (in $3). There's nowhere other than ZLE that can give you the raw ! references, and preexec can't give you $1 in a shell script where history isn't available at all. What you can't do is defer expansions (other than globbing, via noglob) until "inside" the execution of the command (e.g., your shell function). I have a vague recollection that this may relate to you being accustomed to DOS/Windows where expansion of the arguments is done by calling a library after the fact, as opposed to the shell doing all of it first. Anyway, everything you asked about is there, you just need to adjust your thinking about the sequence of events to find the right place to accomplish what you want. Of course this has NOTHING to do with how SAVING the history is configured.