unify cleanup on session termination

This change consolidates similar functionality that was duplicated with
slight variations.  Now, the code path has the same generic structure
with the different functionality confined to their own respective
callbacks.
echo an extra newline in example/ex1.sh

At the end of the example, the extra newlines ensure that your command
prompt displays properly.