From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-workers@zsh.org
Subject: Re: first adventures
Date: Wed, 29 Oct 2014 16:31:43 -0700 [thread overview]
Message-ID: <545178DF.1040600@eastlink.ca> (raw)
In-Reply-To: <141029134624.ZM15681@torch.brasslantern.com>
[-- Attachment #1: Type: text/plain, Size: 5325 bytes --]
On 10/29/2014 01:46 PM, Bart Schaefer wrote:
> On Oct 29, 8:41am, Ray Andrews wrote:
> }
> } So, if there was just some way of matching each line of that output
> } from getpermtext() with the appropriate command, then I'd be close to
> } the finish line.
>
> Maybe if you told us WHY you're trying to extract this particular bit
> of information, in more detail than just --
>
> } if I could then assign that to a shell variable, I'd have exactly what
> } I want: each command would have access to the verbatim command line
> } 'segment' that called it
>
> -- it might be possible to make better suggestions. I've been answering
> on the assumption that you were just trying to learn how the internals
> work, but it seems there's a larger motive.
>
Well, both. I have a real issue, and chewing on it seems like a good
first motivation to dive
into the internals. But I think my questions have been focused enough
that, were it possible to
do as I'm seeking: break up the command line (in the .histfile format as
we've discussed) into
separate individual commands (by semicolons and/or however else that is
done), and be able to
pass that 'literal' command string to the command to which it applies:
whats-my-line()
{
echo "My line was: $some-imaginary-variable"
}
$ whats-my-line $PWD * < > /temp/junk ; what's-my-line '$foo' bar;
whats-my-line "I think that I shall never see"
My line was: $PWD * < > /temp/junk
My line was: '$foo' bar
My line was: "I think that I shall never see"
... then I'd be able to handle the rest.
Really, I just want to grab command arguments 'raw', I look at .histfile
because that's where they
*are* stored raw (except for bangchar expansion, which is fine).
But since you ask about the larger motive (but I waste enough of your
time already):
I like wrappers:
ell is the wrapper around 'ls'. The ,H switch says, 'show me the
'expanded' (or 'real')
command you are about to execute, and write it to history
(for recall with possible modifications, as desired):
Comments are interspersed with screen capture:
$ l ,H main.c*
... it produces a tarted up output:
Sorting All file types Backwards by Modification Time (main.c*):
... and it shows you the 'real' command, and saves it to history:
EXECUTING: ls --time-style=+%F//%T -AGFhrgdt
--group-directories-first --color=always main.c* | egrep '' | egrep
-v "^total"
-rw-r--r-- 1 3.7K 2014-10-28//15:45:56 main.c.unc-backup~
-rw-r--r-- 1 3.7K 2014-10-28//16:21:23 main.c
-rw-r--r-- 1 41 2014-10-28//16:21:23 main.c.unc-backup.md5~
... The last two lines in history:
14561* l ,H main.c*
14562 ls --time-style=+%F//%T -AGFhrgdt --group-directories-first
--color=always main.c* | egrep '' | egrep -v "^total"
... now, I recall and execute the last command in history:
pts/7 HP-y5--5-Debian1 root /aMisc/Z/zsh-5.0.7/Src $ ls
--time-style=+%F//%T -AGFhrgdt --group-directories-first
--color=always main.c* | egrep '' | egrep -v "^total"
-rw-r--r-- 1 3.7K 2014-10-28//15:45:56 main.c.unc-backup~
-rw-r--r-- 1 3.7K 2014-10-28//16:21:23 main.c
-rw-r--r-- 1 41 2014-10-28//16:21:23 main.c.unc-backup.md5~
... and the ouptut it exactly the same because it is exactly the
same 'real' command.
It already works very much as I want, but the scripting is laborious
because the shell can't be
restrained from expanding things. Arguments to the function want to
expand, but that makes
it difficult to show the 'EXECUTING: ...' line because I DONT want any
expansions at all,
just the various arguments from the literal string that I typed. (If
globs expanded you can
imagine the result.)
Oversimplified, I do it like this:
alias l='noglob _l'
function _l ()
{
...
# And once I've cobbled together the 'real' 'ls' command, I use
'eval' to expand any globs
# and it's fine. (Tho I'd like to restrain variable expansion
too, but it's not vital).
echo "$the-big-long-ls-command" >> $HOME/.histfile
fc -R
echo "EXECUTING: $the-big-long-ls-command"
eval "$the-big-long-ls-command"
}
It doesn't matter what I type on CLI, whatever I type goes to history
just the way
I want it. How to get it back? Easy if there was only one command on the
line, but if several:
$ l main.c*; l version.h; l * >! $PWD/file
... .histfile:
14564 l main.c*; l version.h; l * >! $PWD/file
Now, If I could just 'match' each command at execution with the literal
string from whence it
was called, I'd have precisely what I'm looking for: The third call to
ell above would know at
execution that it was called via the literal string: " l * >! $PWD/file
". Knowing the literal string,
I could put together the 'EXECUTING' string with " $PWD " NOT whatever $PWD
evaluates to.
So ... if I can't grab the arguments to a command 'raw', then I'm hoping
that somewhere in the code it might
be possible to tease apart the line in .histfile and send each fragment
to the appropriate command via
a variable. But I think that on principal a command should be able to
grab it's arguments 'raw' if
it wants to. " $@ " = expanded argument list vs: (made up:) " $!@ " =
raw argument list.
Or something ....
next prev parent reply other threads:[~2014-10-29 23:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-26 17:20 Ray Andrews
2014-10-26 17:50 ` Bart Schaefer
2014-10-26 18:04 ` Bart Schaefer
2014-10-26 18:41 ` Ray Andrews
2014-10-26 19:57 ` Ray Andrews
2014-10-26 21:04 ` Bart Schaefer
2014-10-27 3:48 ` Ray Andrews
2014-10-27 6:08 ` Bart Schaefer
2014-10-26 17:52 ` Peter Stephenson
2014-10-28 17:48 ` Ray Andrews
2014-10-29 4:05 ` Bart Schaefer
2014-10-29 15:41 ` Ray Andrews
2014-10-29 20:46 ` Bart Schaefer
2014-10-29 23:31 ` Ray Andrews [this message]
2014-10-30 4:07 ` Bart Schaefer
2014-10-30 17:22 ` Ray Andrews
2014-10-31 1:59 ` Ray Andrews
2014-10-31 2:59 ` Bart Schaefer
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=545178DF.1040600@eastlink.ca \
--to=rayandrews@eastlink.ca \
--cc=zsh-workers@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).