The roshask tool does something similar to what you ask for.
roshask
https://github.com/acowley/roshask