Skip to content

Commit

Permalink
#807: Expect aliases declared with equal sign too
Browse files Browse the repository at this point in the history
This fixes #807
  • Loading branch information
scorphus committed May 3, 2018
1 parent 1d01d38 commit fd31747
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions tests/shells/test_fish.py
Expand Up @@ -16,7 +16,8 @@ def Popen(self, mocker):
mock.return_value.stdout.read.side_effect = [(
b'cd\nfish_config\nfuck\nfunced\nfuncsave\ngrep\nhistory\nll\nls\n'
b'man\nmath\npopd\npushd\nruby'),
b'alias fish_key_reader /usr/bin/fish_key_reader\nalias g git']
(b'alias fish_key_reader /usr/bin/fish_key_reader\nalias g git\n'
b'alias alias_with_equal_sign=echo\nfoo_invalid'), b'f1\nf2', b'']
return mock

@pytest.mark.parametrize('key, value', [
Expand Down Expand Up @@ -69,7 +70,9 @@ def test_get_aliases(self, shell):
'pushd': 'pushd',
'ruby': 'ruby',
'g': 'git',
'fish_key_reader': '/usr/bin/fish_key_reader'}
'fish_key_reader': '/usr/bin/fish_key_reader',
'alias_with_equal_sign': 'echo'}
assert shell.get_aliases() == {'f1': 'f1', 'f2': 'f2'}

def test_app_alias(self, shell):
assert 'function fuck' in shell.app_alias('fuck')
Expand Down
14 changes: 11 additions & 3 deletions thefuck/shells/fish.py
Expand Up @@ -20,9 +20,17 @@ def _get_functions(overridden):
def _get_aliases(overridden):
aliases = {}
proc = Popen(['fish', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
alias_out = proc.stdout.read().decode('utf-8').strip().split('\n')
for alias in alias_out:
name, value = alias.replace('alias ', '', 1).split(' ', 1)
alias_out = proc.stdout.read().decode('utf-8').strip()
if not alias_out:
return aliases
for alias in alias_out.split('\n'):
for separator in (' ', '='):
split_alias = alias.replace('alias ', '', 1).split(separator, 1)
if len(split_alias) == 2:
name, value = split_alias
break
else:
continue
if name not in overridden:
aliases[name] = value
return aliases
Expand Down

0 comments on commit fd31747

Please sign in to comment.