mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
fix(fish.get_aliases): do not include overridden aliases
Fish Shell overrides some shell commands, such as `cd` and `ls` and therefore some rules fail to match. The following aliases are excluded by default: * cd * grep * ls * man * open To change them, one can use the `TF_OVERRIDDEN_ALIASES` environment variable such as: ``` set TF_OVERRIDDEN_ALIASES 'cd,grep,ls' ``` Fix #262
This commit is contained in:
parent
5abab8bd1e
commit
891fbe7ed1
@ -116,18 +116,34 @@ class TestFish(object):
|
|||||||
def Popen(self, mocker):
|
def Popen(self, mocker):
|
||||||
mock = mocker.patch('thefuck.shells.Popen')
|
mock = mocker.patch('thefuck.shells.Popen')
|
||||||
mock.return_value.stdout.read.return_value = (
|
mock.return_value.stdout.read.return_value = (
|
||||||
b'fish_config\nfuck\nfunced\nfuncsave\ngrep\nhistory\nll\nmath')
|
b'cd\nfish_config\nfuck\nfunced\nfuncsave\ngrep\nhistory\nll\nls\n'
|
||||||
|
b'man\nmath\npopd\npushd\nruby')
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def environ(self, monkeypatch):
|
||||||
|
data = {'TF_OVERRIDDEN_ALIASES': 'cd, ls, man, open'}
|
||||||
|
monkeypatch.setattr('thefuck.shells.os.environ', data)
|
||||||
|
return data
|
||||||
|
|
||||||
|
@pytest.mark.usefixture('environ')
|
||||||
|
def test_get_overridden_aliases(self, shell, environ):
|
||||||
|
assert shell._get_overridden_aliases() == ['cd', 'ls', 'man', 'open']
|
||||||
|
|
||||||
@pytest.mark.parametrize('before, after', [
|
@pytest.mark.parametrize('before, after', [
|
||||||
|
('cd', 'cd'),
|
||||||
('pwd', 'pwd'),
|
('pwd', 'pwd'),
|
||||||
('fuck', 'fish -ic "fuck"'),
|
('fuck', 'fish -ic "fuck"'),
|
||||||
('find', 'find'),
|
('find', 'find'),
|
||||||
('funced', 'fish -ic "funced"'),
|
('funced', 'fish -ic "funced"'),
|
||||||
|
('grep', 'grep'),
|
||||||
('awk', 'awk'),
|
('awk', 'awk'),
|
||||||
('math "2 + 2"', r'fish -ic "math \"2 + 2\""'),
|
('math "2 + 2"', r'fish -ic "math \"2 + 2\""'),
|
||||||
|
('man', 'man'),
|
||||||
|
('open', 'open'),
|
||||||
('vim', 'vim'),
|
('vim', 'vim'),
|
||||||
('ll', 'fish -ic "ll"')]) # Fish has no aliases but functions
|
('ll', 'fish -ic "ll"'),
|
||||||
|
('ls', 'ls')]) # Fish has no aliases but functions
|
||||||
def test_from_shell(self, before, after, shell):
|
def test_from_shell(self, before, after, shell):
|
||||||
assert shell.from_shell(before) == after
|
assert shell.from_shell(before) == after
|
||||||
|
|
||||||
@ -149,10 +165,12 @@ class TestFish(object):
|
|||||||
'fuck': 'fuck',
|
'fuck': 'fuck',
|
||||||
'funced': 'funced',
|
'funced': 'funced',
|
||||||
'funcsave': 'funcsave',
|
'funcsave': 'funcsave',
|
||||||
'grep': 'grep',
|
|
||||||
'history': 'history',
|
'history': 'history',
|
||||||
'll': 'll',
|
'll': 'll',
|
||||||
'math': 'math'}
|
'math': 'math',
|
||||||
|
'popd': 'popd',
|
||||||
|
'pushd': 'pushd',
|
||||||
|
'ruby': 'ruby'}
|
||||||
|
|
||||||
def test_app_alias(self, shell):
|
def test_app_alias(self, shell):
|
||||||
assert 'function fuck' in shell.app_alias()
|
assert 'function fuck' in shell.app_alias()
|
||||||
|
@ -106,10 +106,18 @@ class Bash(Generic):
|
|||||||
|
|
||||||
|
|
||||||
class Fish(Generic):
|
class Fish(Generic):
|
||||||
|
|
||||||
|
def _get_overridden_aliases(self):
|
||||||
|
overridden_aliases = os.environ.get('TF_OVERRIDDEN_ALIASES', '').strip()
|
||||||
|
if overridden_aliases:
|
||||||
|
return [alias.strip() for alias in overridden_aliases.split(',')]
|
||||||
|
else:
|
||||||
|
return ['cd', 'grep', 'ls', 'man', 'open']
|
||||||
|
|
||||||
def app_alias(self):
|
def app_alias(self):
|
||||||
return ("function fuck -d 'Correct your previous console command'\n"
|
return ("set TF_ALIAS fuck\n"
|
||||||
|
"function fuck -d 'Correct your previous console command'\n"
|
||||||
" set -l exit_code $status\n"
|
" set -l exit_code $status\n"
|
||||||
" set -l TF_ALIAS fuck\n"
|
|
||||||
" set -l eval_script"
|
" set -l eval_script"
|
||||||
" (mktemp 2>/dev/null ; or mktemp -t 'thefuck')\n"
|
" (mktemp 2>/dev/null ; or mktemp -t 'thefuck')\n"
|
||||||
" set -l fucked_up_commandd $history[1]\n"
|
" set -l fucked_up_commandd $history[1]\n"
|
||||||
@ -122,10 +130,11 @@ class Fish(Generic):
|
|||||||
"end")
|
"end")
|
||||||
|
|
||||||
def get_aliases(self):
|
def get_aliases(self):
|
||||||
|
overridden = self._get_overridden_aliases()
|
||||||
proc = Popen('fish -ic functions', stdout=PIPE, stderr=DEVNULL,
|
proc = Popen('fish -ic functions', stdout=PIPE, stderr=DEVNULL,
|
||||||
shell=True)
|
shell=True)
|
||||||
functions = proc.stdout.read().decode('utf-8').strip().split('\n')
|
functions = proc.stdout.read().decode('utf-8').strip().split('\n')
|
||||||
return {function: function for function in functions}
|
return {func: func for func in functions if func not in overridden}
|
||||||
|
|
||||||
def _expand_aliases(self, command_script):
|
def _expand_aliases(self, command_script):
|
||||||
aliases = self.get_aliases()
|
aliases = self.get_aliases()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user