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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8403 invoked from network); 15 Apr 2023 22:48:24 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Apr 2023 22:48:24 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1681598904; b=HsVlivc3mF43bkXXX5Psd4xbtjq82nWMAnULdHbeXx8zCVbZ1etOscDd4r7jx56G8/PXivAfnd tPyJRpXw2BCcIA5dH8q3UqCF+XqQXWLaliO7eFDor4T4Mi5bqmUpHkT882kMkUt8tU++vhpkck 7MlkHd9nYykeXu6f/yhOQbeVni/hUWBPqIxdVeTc75bqiFmn8dHw88OSN7cqpSUANjrn95gz8f aiU1jJKHktBcVZdXTPQ1nxi7fplL+Izwef/7fn2RIp/2ONCjLYHD5Fai0xA2s1x5zA7/jGRXy+ SRGRiylZgSWXg8xi3jZ2jyW1EN9ESBfAouGs+cXKFwRhAg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta03.eastlink.ca) smtp.remote-ip=24.224.136.9; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1681598904; bh=7HZ+Gdf/4M+JnpIgvozr8WoDMTPbCOElIhLPrWtg0PE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:To:Subject:MIME-Version:Date:Message-ID:DKIM-Signature; b=qQ6c9/2TE/HyppfLAdD6TZVsxinS3D+xobcsgcpS3o46pW0S2+gTdY3A/w8ON63hJWjocesYrr g5DFvK6piOGKKwD1rorN6RgGZ6vv07CjPQGHdvx5Eo8sBLVy9HRuSRH1KMlJWITAqzfxhxsuv3 birWSaCilcOnNr8qnr0Pl+VaaY0tHJhtA6QpOIHUmZZ+SAVMSi9jpxRYtI1oPRo5zCjyiV2HyR CROWYn3K57BjZDt/tBCwC17ZzgmcxhdWhDTVF26G2U2/fWhFinQBZcAJbellwv9y9QB1X8NiUY V8G0TdrTMTWx99MJjZjcKQamW++TBVwE8CD09nmC9t+lVw==; 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:In-reply-to:From:References:To:Subject:MIME-version:Date: Message-id:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Ik7HcGnCCHI+8LVal+uCD7yEItsOMuaxzC1orgEyWeE=; b=BvM+9P9ZXJyIM6RT8bsBSiUo0t VG10if3r+NkzL2xlPoh48ozmoSf3Yo29fLRza4YU0SZ2xD/A0XAMA7pv14Hpl7rrgPjAd1N0FX69E cFtWxNySxkdZPGVNmav3fK6/INOnVg6s0BCeld7IuXEHyMYoop5puB2iFYuBGPxiQKGWT3IPX39+b 2s5jS0d3mlNnDRRYbt3IOUExLJj+wgkSZMGP0k+nX4NrSZKBVeogYNLxvdK/jAk1SfAdqr51zDZsY IV3I3ISRgB8izLslxZcV14/t48rNxl3isiAwPMCzrfQShJ4ltISsCJAnhHs+rxZTm7/XD3i8p/Wc7 bkoCR4rQ==; Received: by zero.zsh.org with local id 1pnogx-000PGP-HW; Sat, 15 Apr 2023 22:48:23 +0000 Authentication-Results: zsh.org; iprev=pass (mta03.eastlink.ca) smtp.remote-ip=24.224.136.9; dmarc=none header.from=eastlink.ca; arc=none Received: from mta03.eastlink.ca ([24.224.136.9]:43801) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1pnogL-000Oaa-77; Sat, 15 Apr 2023 22:47:46 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta03.eastlink.ca ([24.224.136.9]) with ESMTPS id <0RT6001P3EB5ZU41@mta03.eastlink.ca> for zsh-users@zsh.org; Sat, 15 Apr 2023 19:47:44 -0300 (ADT) Received: from [192.168.0.4] (host-24-207-18-108.public.eastlink.ca [24.207.18.108]) by csp01.eastlink.ca ([71.7.199.166]) with ESMTPSA id nogJpcrknhhvwnogJpz5pe (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Sat, 15 Apr 2023 19:47:44 -0300 X-Authority-Analysis: v=2.4 cv=NdAglUP4 c=1 sm=1 tr=0 ts=643b2990 a=xN66ZtSbq5jdJYpBp7G/jQ==:117 a=xN66ZtSbq5jdJYpBp7G/jQ==:17 a=IkcTkHD0fZMA:10 a=orJqIfCz2V-gl0LOqUYA:9 a=QEXdDO2ut3YA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdelfedgudehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptfgrhicutehnughrvgifshcuoehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgeqnecuggftrfgrthhtvghrnhepiedtjeffvefgtdehgefgteekueeggeeitedutddvvdduteetffdvveelgfeukedunecukfhppedvgedrvddtjedrudekrddutdeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrddukedruddtkedphhgvlhhopegludelvddrudeikedrtddrgegnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Message-id: <8b0f0941-5212-5268-1f9d-d7542990439a@eastlink.ca> Date: Sat, 15 Apr 2023 15:47:43 -0700 MIME-version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: "Pull just the text of a single command" (was Re: .zsh_history) Content-language: en-US To: zsh-users@zsh.org References: <81609CF4-42DA-4E0F-A6E5-C5D58578B4F7@easesoftware.com> <9a1f77ea-ee4e-95ff-a571-5cd3ddce6cb2@eastlink.ca> From: Ray Andrews In-reply-to: Content-type: text/plain; charset=UTF-8; format=flowed Content-transfer-encoding: 8bit X-Seq: 29026 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 2023-04-15 12:47, Bart Schaefer wrote: > I'm not sure which past discussion you're referencing, but it's This goes back to when I first started with Linux.  It was one of my first issues here.  You weighed in on the topic but 'noglob' was the best we did at the time.  Quite possible I was not communicating very well. > So if you want the unaltered text as you work > with it, ZLE is where you get it. That's what I want.  I only refer to history because: $ print -rS "$@" ... as I have it now, does write the command with its tail unexpanded, and, combined with 'noglob' I get pretty much what I want.  But it's a huge labor to do something that should be very simple. > 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). Sounds worth trying. > > 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). That sounds exactly right.  Come to that, an expansion of a call to history -- the ! stuff -- would be the one and only thing I would want pre-expanded.  It's sorta the obvious exception because it's a meta command -- a command to call a command.  Nuts, I'm trying to remember if I ever tried something like that.  If you're recommending it now, you would have recommended it then, and I'd have tried it then ... but I can't remember.  But I know I didn't try anything with zle. > 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. Yeah.  We did conclude that what I was trying to do was a fundamental violation of basic Unix/Linux philosophy. > > 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. I'm not fussy.  Just so long as I can access the tail from within a function, I don't care how that tail gets stored.   It's hard to explain why this matters but most of my wrapper functions are ever more complex massaging of the output of some basic command -- and lots of color.  If I need a modification, rather than edit my own code, what I do is first edit the 'real' command to make the change I want, then when I know what I want, I edit my own code so as to achieve that result.  For example 'l' wraps 'ls': $ l LISTING of "*": All file types, INsensitive. Sorting upside down by: Mod. Time:  18432 [2022-10-09--16:43] 2021-08-12-backup/   1024 [2022-11-12--09:43] Boneyard/   4096 [2022-11-20--10:38] 2022-11-20-backup/  18432 [2022-11-20--14:12] Empty/   4096 [2022-11-28--06:55] Znt/ ...   8649 [2023-03-22--19:54] miscfunctions,8,local files only with changed   8649 [2023-03-22--19:54] miscfunctions  19831 [2023-03-22--20:28] l,4,BUG  x colorized in l X  19831 [2023-03-22--20:28] l Items found: 169 Total bytes in directory "/aWorking/Zsh/Source/Wk": 1.7M Total including subdirs: 25M ... a listing the way I like it to look.  What 'l' actually executes is: $ ls --time-style='+[%F--%H:%M]' --group-directories-first -AFrGgdt --color=always (#i)* 2> /dev/null | sed -r "s/^(.{10} {1,3}[[:digit:]]{1,3} )/ /" | egrep -v '^total' | sed '/;34m\.\x1b\[0m\/$/d' | perl -pe "s|\] (.*?)()|\] \1^[[31;1m\2^[[0m|i" So, using my convoluted method: $ l ,H ... writes the above command to history and then up-arrow retrieves it for editing.  Once I've made whatever change I want to the 'real' command, then I edit my own code so as to implement the modification.  Basically I can edit in two stages.  And the thing is that the '*' and various other expandable things must *not* expand, otherwise the command written to history can become almost infinitely long.  Clear as mud?  Anyway it works marvelously but is convoluted ... unless I can grab the tail, unexpanded, with less trouble.  That way, instead of storing it via history, I can access it some other way.  IOW the only reason I use history is because it shows unexpanded commands. Show me how to do this with zle or preexec and I'll be in heaven.