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

Re: Get the current command line from a function



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.



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