mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 04:48:57 +00:00
Merge pull request #206 from scorphus/fish-shell
Add support to Fish shell
This commit is contained in:
commit
dc53f58b2a
@ -50,6 +50,28 @@ class TestBash(object):
|
|||||||
write.assert_called_once_with('ls\n')
|
write.assert_called_once_with('ls\n')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('isfile')
|
||||||
|
class TestFish(object):
|
||||||
|
@pytest.mark.parametrize('before, after', [
|
||||||
|
('pwd', 'pwd'),
|
||||||
|
('ll', 'll')]) # Fish has no aliases but functions
|
||||||
|
def test_from_shell(self, before, after):
|
||||||
|
assert shells.Fish().from_shell(before) == after
|
||||||
|
|
||||||
|
def test_to_shell(self):
|
||||||
|
assert shells.Fish().to_shell('pwd') == 'pwd'
|
||||||
|
|
||||||
|
def test_put_to_history(self, builtins_open, mocker):
|
||||||
|
mocker.patch('thefuck.shells.time',
|
||||||
|
return_value=1430707243.3517463)
|
||||||
|
shells.Fish().put_to_history('ls')
|
||||||
|
builtins_open.return_value.__enter__.return_value. \
|
||||||
|
write.assert_called_once_with('- cmd: ls\n when: 1430707243\n')
|
||||||
|
|
||||||
|
def test_and_(self):
|
||||||
|
assert shells.Fish().and_('foo', 'bar') == 'foo; and bar'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('isfile')
|
@pytest.mark.usefixtures('isfile')
|
||||||
class TestZsh(object):
|
class TestZsh(object):
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
|
@ -76,6 +76,31 @@ class Bash(Generic):
|
|||||||
return u'{}\n'.format(command_script)
|
return u'{}\n'.format(command_script)
|
||||||
|
|
||||||
|
|
||||||
|
class Fish(Generic):
|
||||||
|
def app_alias(self):
|
||||||
|
return ("function fuck -d 'Correct your previous console command'\n"
|
||||||
|
" set -l exit_code $status\n"
|
||||||
|
" set -l eval_script"
|
||||||
|
" (mktemp 2>/dev/null ; or mktemp -t 'thefuck')\n"
|
||||||
|
" set -l fucked_up_commandd $history[1]\n"
|
||||||
|
" thefuck $fucked_up_commandd > $eval_script\n"
|
||||||
|
" . $eval_script\n"
|
||||||
|
" rm $eval_script\n"
|
||||||
|
" if test $exit_code -ne 0\n"
|
||||||
|
" history --delete $fucked_up_commandd\n"
|
||||||
|
" end\n"
|
||||||
|
"end")
|
||||||
|
|
||||||
|
def _get_history_file_name(self):
|
||||||
|
return os.path.expanduser('~/.config/fish/fish_history')
|
||||||
|
|
||||||
|
def _get_history_line(self, command_script):
|
||||||
|
return u'- cmd: {}\n when: {}\n'.format(command_script, int(time()))
|
||||||
|
|
||||||
|
def and_(self, *commands):
|
||||||
|
return '; and '.join(commands)
|
||||||
|
|
||||||
|
|
||||||
class Zsh(Generic):
|
class Zsh(Generic):
|
||||||
def app_alias(self):
|
def app_alias(self):
|
||||||
return "\nalias fuck='eval $(thefuck $(fc -ln -1 | tail -n 1)); fc -R'\n"
|
return "\nalias fuck='eval $(thefuck $(fc -ln -1 | tail -n 1)); fc -R'\n"
|
||||||
@ -126,6 +151,7 @@ class Tcsh(Generic):
|
|||||||
|
|
||||||
shells = defaultdict(lambda: Generic(), {
|
shells = defaultdict(lambda: Generic(), {
|
||||||
'bash': Bash(),
|
'bash': Bash(),
|
||||||
|
'fish': Fish(),
|
||||||
'zsh': Zsh(),
|
'zsh': Zsh(),
|
||||||
'-csh': Tcsh(),
|
'-csh': Tcsh(),
|
||||||
'tcsh': Tcsh()})
|
'tcsh': Tcsh()})
|
||||||
@ -136,7 +162,7 @@ def _get_shell():
|
|||||||
shell = Process(os.getpid()).parent().cmdline()[0]
|
shell = Process(os.getpid()).parent().cmdline()[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
shell = Process(os.getpid()).parent.cmdline[0]
|
shell = Process(os.getpid()).parent.cmdline[0]
|
||||||
return shells[shell]
|
return shells[os.path.basename(shell)]
|
||||||
|
|
||||||
|
|
||||||
def from_shell(command):
|
def from_shell(command):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user