Rework history and last command handling in mdb_shell