Fix nushell history newline and multiline entries

put_to_history wrote entries without a trailing newline, so fixed
commands concatenated onto one line, and backslash-continued
multiline entries were read back as broken fragments. Join
continuations when reading and terminate entries with a newline,
matching the fish adapter convention.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Alexander
2026-09-13 20:42:30 +02:00
parent a5c675cdea
commit 624938c284
2 changed files with 92 additions and 1 deletions
+52
View File
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
import io
import pytest
from thefuck.shells import Nushell
@pytest.mark.usefixtures('no_memoize')
class TestNushell(object):
@pytest.fixture
def shell(self, mocker, tmp_path):
shell = Nushell()
mocker.patch.object(shell, '_get_history_file_name',
return_value=str(tmp_path / 'history.txt'))
return shell
@pytest.fixture
def history_file(self, shell):
def write(content):
with io.open(shell._get_history_file_name(), 'w',
encoding='utf-8') as history:
history.write(content)
return write
def test_put_to_history_writes_trailing_newline(self, shell,
history_file):
history_file(u'')
shell.put_to_history('cmd1')
shell.put_to_history('cmd2')
with io.open(shell._get_history_file_name(), 'r',
encoding='utf-8') as history:
assert history.read() == u'cmd1\ncmd2\n'
def test_get_history_after_put_to_history(self, shell, history_file):
history_file(u'')
shell.put_to_history('cmd1')
shell.put_to_history('cmd2')
assert list(shell.get_history()) == ['cmd1', 'cmd2']
def test_get_history_joins_backslash_continuations(self, shell,
history_file):
history_file(u'foo \\\nbar\nls\n')
assert list(shell.get_history()) == [u'foo bar', 'ls']
def test_get_history_when_file_missing(self, shell):
assert list(shell.get_history()) == []
def test_get_history_respects_history_limit(self, shell, history_file,
settings):
settings.history_limit = 2
history_file(u'a\nb\nc\n')
assert list(shell.get_history()) == ['b', 'c']