diff --git a/babi.py b/babi.py index d40fac4..18c1355 100644 --- a/babi.py +++ b/babi.py @@ -227,8 +227,10 @@ class Status: yield finally: for k, v in self._history.items(): - with open(os.path.join(history_dir, k), 'a+') as f: - f.write('\n'.join(v[self._history_orig_len[k]:]) + '\n') + new_history = v[self._history_orig_len[k]:] + if new_history: + with open(os.path.join(history_dir, k), 'a+') as f: + f.write('\n'.join(new_history) + '\n') def update(self, status: str) -> None: self._status = status diff --git a/tests/search_test.py b/tests/search_test.py index 98e951f..c77acd9 100644 --- a/tests/search_test.py +++ b/tests/search_test.py @@ -296,3 +296,13 @@ def test_search_reverse_search_keeps_current_text_displayed(): h.press('^R') h.await_text('search(reverse-search)``: ohai') h.press('^C') + + +def test_search_history_extra_blank_lines(xdg_data_home): + with run() as h, and_exit(h): + h.press('^W') + h.press_and_enter('hello') + with run() as h, and_exit(h): + pass + contents = xdg_data_home.join('babi/history/search').read() + assert contents == 'hello\n'