Save and reload the history after each command finishes