From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29670 invoked by alias); 30 Oct 2014 04:07:42 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33572 Received: (qmail 20870 invoked from network); 30 Oct 2014 04:07:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=GLe/yVJP c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=IsjdXnEJplYBaj7h_KAA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <141029210738.ZM15833@torch.brasslantern.com> Date: Wed, 29 Oct 2014 21:07:37 -0700 In-reply-to: <545178DF.1040600@eastlink.ca> Comments: In reply to Ray Andrews "Re: first adventures" (Oct 29, 4:31pm) References: <544D2D6F.8030505@eastlink.ca> <20141026175257.2611487b@pws-pc.ntlworld.com> <544FD6DD.7010806@eastlink.ca> <141028210510.ZM10784@torch.brasslantern.com> <54510A96.20009@eastlink.ca> <141029134624.ZM15681@torch.brasslantern.com> <545178DF.1040600@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: first adventures MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Oct 29, 4:31pm, Ray Andrews wrote: > > 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: The problem with asking focused questions is that they feed on one's preconceived notions of what needs to be done, rather than revealing what has already BEEN done ... torch% setopt DEBUG_BEFORE_CMD (That's the default, but just in case.) torch% TRAPDEBUG() { print -u2 "XX $ZSH_DEBUG_CMD XX" } torch% print $path * > /dev/null XX print $path * > /dev/null XX torch% This only gets you as far as what the grammar calls a "sublist", so a pipeline will get put into $ZSH_DEBUG_CMD in its entirety, but a new trap is run after each semicolon: torch% print $path * > /dev/null ; print foo | grep bar XX print $path * > /dev/null XX XX print foo | grep bar XX torch% print $(echo foo | grep bar) XX print $(echo foo | grep bar) XX XX echo foo | grep bar XX torch% Also for structured commands (loops, if-then) the DEBUG trap is called once for the entire structure and then again for each sublist inside: torch% repeat 3 repeat> do print foo repeat> done XX repeat 3 do print foo done XX XX print foo XX foo XX print foo XX foo XX print foo XX foo torch% This means you can work around the pipeline thing by using braces: torch% { print $path * > /dev/null } && { print foo } | { grep bar } XX { print $path * > /dev/null } && { print foo } | { grep bar } XX XX print $path * > /dev/null XX XX print foo XX XX grep bar XX torch% The commands that appear inside the debug trap are not themselves debugged, so you can examine other state there to decide for example whether you want to copy $ZSH_DEBUG_CMD into another variable that your wrapper can then examine. (( $#functrace == 1 )) is probably a good test for whether you are at the shell prompt, e.g.: typeset -g THIS_TOPLEVEL_CMD TRAPDEBUG() { (( $#functrace == 1 )) && THIS_TOPLEVEL_CMD="$ZSH_DEBUG_CMD" } Then your ell function can look at $THIS_TOPLEVEL_CMD like you want. One final word: > echo "$the-big-long-ls-command" >> $HOME/.histfile > fc -R Ouch; please don't do that. print -S "$THIS_TOPLEVEL_CMD"