Bash/Shell: How to add to history without removing the callee history function

49 views Asked by At
history -s

^ Command will add to history. However, it will also not allow the callee function to remain in the history.

To clarify with example:

When we have a function:

history.demo() {

  echo "args: $@"

  history -s "echo HI WORLD"
}
export -f history.demo;

And call this function in terminal

history.demo 1 a

What I would like to see saved in the history is

history.demo 1 a
echo HI WORLD

However, what I do see is only

echo HI WORLD

How can we get the original and the add-on into bash history?

1

There are 1 answers

0
user7858768 On

Looks like the following is doing the trick (thank you r2evans@ for the pointer)

history.demo() {
  echo "args: $@"

  history -s "${FUNCNAME[0]} $@"
  history -s "echo HI WORLD"
}
export -f history.demo;