From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: append to history entry?
Date: Wed, 28 Dec 2016 19:27:39 -0800 [thread overview]
Message-ID: <0038ee8e-fb30-5cff-a1b5-f361d78d8f59@eastlink.ca> (raw)
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.
next prev parent reply other threads:[~2016-12-29 3:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-26 23:16 Ray Andrews
2016-12-27 1:28 ` Ray Andrews
2016-12-27 4:47 ` Bart Schaefer
[not found] ` <5288b537-f06a-d18a-60ea-1f962856c80c__41345.3811700039$1482803962$gmane$org@eastlink.ca>
2016-12-27 12:55 ` Daniel Shahaf
2016-12-27 16:00 ` Bart Schaefer
2016-12-27 18:23 ` Ray Andrews
2016-12-27 19:09 ` Bart Schaefer
2016-12-27 23:16 ` Ray Andrews
2016-12-27 23:55 ` Bart Schaefer
2016-12-28 0:57 ` Ray Andrews
2016-12-28 6:04 ` Bart Schaefer
2016-12-28 17:39 ` Ray Andrews
2016-12-28 18:22 ` Bart Schaefer
2016-12-28 19:20 ` Ray Andrews
2016-12-28 21:24 ` Ray Andrews
[not found] ` <3b8fe027-d7fb-25fb-bc05-9ecd3a91b08f__38422.8622112007$1482960347$gmane$org@eastlink.ca>
2016-12-28 23:34 ` Daniel Shahaf
2016-12-29 0:51 ` Bart Schaefer
2016-12-29 3:27 ` Ray Andrews [this message]
[not found] ` <f87d7f79-3529-d832-eed5-83d4130ea128__16005.139592062$1482888562$gmane$org@eastlink.ca>
2016-12-28 5:28 ` Daniel Shahaf
2016-12-28 6:31 ` Bart Schaefer
2016-12-28 16:33 ` Ray Andrews
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0038ee8e-fb30-5cff-a1b5-f361d78d8f59@eastlink.ca \
--to=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).