From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19593 invoked by alias); 29 Dec 2016 03:27:50 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22310 Received: (qmail 20472 invoked from network); 29 Dec 2016 03:27:50 -0000 X-Qmail-Scanner-Diagnostics: from mta02.eastlink.ca by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(24.224.136.13):SA:0(-3.8/5.0):. Processed in 1.782881 secs); 29 Dec 2016 03:27:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RP_MATCHES_RCVD,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: rayandrews@eastlink.ca X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.eastlink.ca designates 24.224.136.13 as permitted sender) MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset=utf-8; format=flowed X-Authority-Analysis: v=2.2 cv=ZvqvEJzG c=1 sm=1 tr=0 a=28Ntk8jg+Dho8ABWn/CRtA==:117 a=28Ntk8jg+Dho8ABWn/CRtA==:17 a=IkcTkHD0fZMA:10 a=waxTYiRYMH5FdR3cyVkA:9 a=QEXdDO2ut3YA:10 X-EL-IP-NOAUTH: 24.207.16.108 Subject: Re: append to history entry? To: zsh-users@zsh.org References: <99549001-5744-c36f-a4dc-404071aba08a@eastlink.ca> <161227110954.ZM1153@torch.brasslantern.com> <0a48db86-b41a-283c-8193-e2766aa5d30b@eastlink.ca> <161227155552.ZM2385@torch.brasslantern.com> <161227220458.ZM3240@torch.brasslantern.com> <161228102207.ZM5358@torch.brasslantern.com> <388b7c6d-8740-a487-1281-6f56b5cbc8e4@eastlink.ca> <3b8fe027-d7fb-25fb-bc05-9ecd3a91b08f__38422.8622112007$1482960347$gmane$org@eastlink.ca> <20161228233401.GA5901@fujitsu.shahaf.local2> From: Ray Andrews Message-id: <0038ee8e-fb30-5cff-a1b5-f361d78d8f59@eastlink.ca> Date: Wed, 28 Dec 2016 19:27:39 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 In-reply-to: <20161228233401.GA5901@fujitsu.shahaf.local2> On 28/12/16 03:34 PM, Daniel Shahaf wrote: > > Just consider the following cases (there are more, but you should get > the gist): Sure, no surprise there, of course only the parser knows one semicolon from the next but as Bart says, the history string is saved way before the parser gets to it, so it sounds like I can have my strings, but not robustly check for separation of commands. > What are you trying to do now? This is no longer your original > question about recording the hostname in history. > > Is this about 'rap' being called in the middle of a command lineā€¦? It's mostly for my command wrappers. The thing is to make it possible to see the 'real' command being run by the wrapper. I have it mostly satisfactory but the method is belaboured. For example 'l' wraps 'ls'. If I do: /boot $ l ,R *amd64 ( 'R' meaning sort and tabulate from the right) in my /boot directory I get: | | || |1 4153384 2016-12-17/09:56:35 vmlinuz-4.8.0-2-amd64|| || 1 3161213 2016-12-17/09:56:35 System.map-4.8.0-2-amd64|| || 1 17655948 2016-12-27/15:59:03 initrd.img-4.8.0-2-amd64|| || 1 183632 2016-12-17/09:56:35 config-4.8.0-2-amd64|| || |but, what did the wrapper do to get that? It did this: $ ls -AGFrgt --time-style=+%F/%T --group-directories-first *amd64 | egrep -v '^total' | rev | sort -r | column -t | rev | cut --delimiter=' ' --fields=3- How it works is that I start the function thusly: alias l='noglob _l' function _l () { .... process various switches, cobbling together the real command ending up with: _execute $command-string } ... and '_execute' essentially does this: | ||_execute ()|| ||{ || ||||print -rS "$*"|| || echo "\nEXECUTING: ${@//'\'/\\\\}\n"||( more protecting backslashes :( ) || eval "$@"|| ||}|| | ... 'eval' of course expands and executes BUT the command has been pushed to history without glob expansion (which would obviously be impractical in many situations) so that I can recall the 'real' command as I choose. That's useful for debugging the wrapper -- if the wrapper screws up, I just recall the real command and find out where the issue is. Also, I might want to modify the real command in some way and re-execute it since the wrappers themselves only handle routine usage. As it is now, variables are expanded which is no huge problem but if there was some way of grabbing the arguments to the command unexpanded I could just chew on those so that the command pushed to history was totally unexpanded as tho I had typed the real command in by hand. And of course 'eval' would take care of everything as far as execution anyway. The only time it gets unworkable is if some variable contains something huge, but 99% of the time, what I have now is functional, but on principal I'd still like to be able to have my entire command string unaltered , push the constructed real command to history with wildcards and variables as typed, and just have 'eval' expand everything as needed. I know it's sorta the opposite of what zsh is for, but having the real command available for recall can be hugely useful. Here's another example: /boot $ f ,Hd zsh* / EXECUTING: find -H -O3 / -warn -xdev -iname "zsh*" -type d | grep -i --color=always zsh /etc/zsh-virgin /usr/share/zsh ... up arrow brings the real command right back in case I want to play with it some how or just see what the wrapper actually did.