From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: first adventures
Date: Wed, 29 Oct 2014 21:07:37 -0700 [thread overview]
Message-ID: <141029210738.ZM15833@torch.brasslantern.com> (raw)
In-Reply-To: <545178DF.1040600@eastlink.ca>
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"
next prev parent reply other threads:[~2014-10-30 4:07 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
2014-10-30 4:07 ` Bart Schaefer [this message]
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=141029210738.ZM15833@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--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).