help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Bash instrumentation


From: Reuben Garrett
Subject: [Help-bash] Bash instrumentation
Date: Sun, 26 Jan 2014 22:38:49 -0600

I'm working on a project that needs to incrementally capture interesting
artifacts of a shell session, in order to lead an interactive user towards
a particular goal. For example, a developer could specify a unit test that
would evaluate (after each interactive command) whether the desired state
has been reached (e.g. a file present with expected signature (`grep`),
certain processes running (`ps`) or connections open (`netstat`), et
cetera). From there it would take other actions according to a given
workflow (such as automatically commit to git when a command succeeds or
satisfies the unit test). This is sort of just scratching the surface, but
the thrust of my interest with Bash is to wrap an interactive shell session
with a suite of behavioral enhancements and special handling — sort of like
a command-line IDE, for interactive shell scripting.

My question is whether Bash exposes any hooks or other interfaces to
facilitate an AOP-style before/after/around advice. COMMAND_PROMPT works
alright for the "after" portion since it can examine the last command line
and exit status — however I'm having difficulty finding anything to hook
onto the "before" portion. A key goal there would be to capture the
standard input and standard output of a pipeline, e.g. by adding `tee
capturefile` to each end of a pipeline. Generally, though, the ideal
solution would enable my app to transform the command line before it's
executed. Bash's `read -e` builtin comes close to addressing my need since
readline seems to provide tab-completion of filenames — however I
ultimately want something that feels genuinely like Bash (e.g. with
tab-completion of executables in the user's $PATH), while still delegating
decisions about which command to execute. Obviously I could accomplish this
very easily by requiring the user to prepend each command line with an
invocation to my app (which in turn does its own transformation and
delegation however I like) — but that wouldn't feel natural to someone
who's hacking away happily, and puts my tooling in the user's way.

I've toyed around with different mashups of `tee`, `script`, and i/o
redirection of a new bash session — but without much luck. Are there any
best practices in this area (shell instrumentation) that don't require
exotic tooling or home-brewed modifications to Bash? Or if not, would
advice-based instrumentation be an interesting feature to consider for
Bash? I'm willing to explore and contribute if it's a viable feature set.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]