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

Re: Get the current command line from a function



Hi.

On Tue 2009-09-15 20:31, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
proclaimed:
> On Sep 15, 12:19pm, Frank Blendinger wrote:
> }
> } I would like to get the entered command line from a function, just like
> } !!, but at an earlier time. An example:
> } 
> }     foo -x -y | my-func -z
> } 
> } I'd like to get the whole line within my-func, so obviously $0 $* don't
> } work. Is there a way to do that?
> 
> So what you mean is that you want "my-func" to be able to access the
> string "foo -x -y | my-func -z" ?  Or you mean something else, such
> as the contents of the current line of the function body?
> 
> If the former, then in an interactive shell only (so history is active)
> you can do
> 
>     zmodload zsh/parameter
> 
> and then refer to
> 
>     $history[$HISTCMD]
> 
> to get the currently-executing history event.  In the general case,
> though (e.g., in a shell script) it is not possible to do that.

That was exactly what I was looking for. Thanks!


Greetings,
Frank

-- 
Frank Blendinger | fb(at)intoxicatedmind.net | GPG: 0x0BF2FE7A
Fingerprint: BB64 F2B8 DFD8 BF90 0F2E 892B 72CF 7A41 0BF2 FE7A

Attachment: signature.asc
Description: Digital signature



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