Improve terminal history behavior