Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: first adventures

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:

       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 ....

Messages sorted by: Reverse Date, Date, Thread, Author