mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
#402: Don't invoke bash for getting aliases
This commit is contained in:
parent
f7f0660114
commit
7ce4307c87
@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
from thefuck.shells import Bash
|
from thefuck.shells import Bash
|
||||||
|
|
||||||
@ -11,14 +12,12 @@ class TestBash(object):
|
|||||||
return Bash()
|
return Bash()
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def Popen(self, mocker):
|
def shell_aliases(self):
|
||||||
mock = mocker.patch('thefuck.shells.bash.Popen')
|
os.environ['TF_SHELL_ALIASES'] = (
|
||||||
mock.return_value.stdout.read.return_value = (
|
'alias fuck=\'eval $(thefuck $(fc -ln -1))\'\n'
|
||||||
b'alias fuck=\'eval $(thefuck $(fc -ln -1))\'\n'
|
'alias l=\'ls -CF\'\n'
|
||||||
b'alias l=\'ls -CF\'\n'
|
'alias la=\'ls -A\'\n'
|
||||||
b'alias la=\'ls -A\'\n'
|
'alias ll=\'ls -alF\'')
|
||||||
b'alias ll=\'ls -alF\'')
|
|
||||||
return mock
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('before, after', [
|
@pytest.mark.parametrize('before, after', [
|
||||||
('pwd', 'pwd'),
|
('pwd', 'pwd'),
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from subprocess import Popen, PIPE
|
|
||||||
import os
|
import os
|
||||||
from ..conf import settings
|
from ..conf import settings
|
||||||
from ..utils import DEVNULL, memoize, cache
|
from ..utils import memoize
|
||||||
from .generic import Generic
|
from .generic import Generic
|
||||||
|
|
||||||
|
|
||||||
@ -9,7 +8,7 @@ class Bash(Generic):
|
|||||||
def app_alias(self, fuck):
|
def app_alias(self, fuck):
|
||||||
alias = "TF_ALIAS={0}" \
|
alias = "TF_ALIAS={0}" \
|
||||||
" alias {0}='PYTHONIOENCODING=utf-8" \
|
" alias {0}='PYTHONIOENCODING=utf-8" \
|
||||||
" TF_CMD=$(thefuck $(fc -ln -1)) && " \
|
" TF_CMD=$(TF_SHELL_ALIASES=$(alias) thefuck $(fc -ln -1)) && " \
|
||||||
" eval $TF_CMD".format(fuck)
|
" eval $TF_CMD".format(fuck)
|
||||||
|
|
||||||
if settings.alter_history:
|
if settings.alter_history:
|
||||||
@ -24,13 +23,10 @@ class Bash(Generic):
|
|||||||
return name, value
|
return name, value
|
||||||
|
|
||||||
@memoize
|
@memoize
|
||||||
@cache('.bashrc', '.bash_profile')
|
|
||||||
def get_aliases(self):
|
def get_aliases(self):
|
||||||
proc = Popen(['bash', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
|
raw_aliases = os.environ.get('TF_SHELL_ALIASES', '').split('\n')
|
||||||
return dict(
|
return dict(self._parse_alias(alias)
|
||||||
self._parse_alias(alias)
|
for alias in raw_aliases if alias and '=' in alias)
|
||||||
for alias in proc.stdout.read().decode('utf-8').split('\n')
|
|
||||||
if alias and '=' in alias)
|
|
||||||
|
|
||||||
def _get_history_file_name(self):
|
def _get_history_file_name(self):
|
||||||
return os.environ.get("HISTFILE",
|
return os.environ.get("HISTFILE",
|
||||||
|
@ -26,7 +26,7 @@ class Zsh(Generic):
|
|||||||
|
|
||||||
@memoize
|
@memoize
|
||||||
def get_aliases(self):
|
def get_aliases(self):
|
||||||
raw_aliases = os.environ['TF_SHELL_ALIASES'].split('\n')
|
raw_aliases = os.environ.get('TF_SHELL_ALIASES', '').split('\n')
|
||||||
return dict(self._parse_alias(alias)
|
return dict(self._parse_alias(alias)
|
||||||
for alias in raw_aliases if alias and '=' in alias)
|
for alias in raw_aliases if alias and '=' in alias)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user