1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-20 20:09:07 +00:00

#402: Don't invoke zsh for getting aliases

This commit is contained in:
nvbn 2016-03-01 01:21:51 +03:00
parent 46f2351907
commit f7f0660114
2 changed files with 16 additions and 19 deletions

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import os
import pytest
from thefuck.shells.zsh import Zsh
@ -11,14 +12,12 @@ class TestZsh(object):
return Zsh()
@pytest.fixture(autouse=True)
def Popen(self, mocker):
mock = mocker.patch('thefuck.shells.zsh.Popen')
mock.return_value.stdout.read.return_value = (
b'fuck=\'eval $(thefuck $(fc -ln -1 | tail -n 1))\'\n'
b'l=\'ls -CF\'\n'
b'la=\'ls -A\'\n'
b'll=\'ls -alF\'')
return mock
def shell_aliases(self):
os.environ['TF_SHELL_ALIASES'] = (
'fuck=\'eval $(thefuck $(fc -ln -1 | tail -n 1))\'\n'
'l=\'ls -CF\'\n'
'la=\'ls -A\'\n'
'll=\'ls -alF\'')
@pytest.mark.parametrize('before, after', [
('fuck', 'eval $(thefuck $(fc -ln -1 | tail -n 1))'),

View File

@ -1,16 +1,17 @@
from subprocess import Popen, PIPE
from time import time
import os
from ..conf import settings
from ..utils import DEVNULL, memoize, cache
from ..utils import memoize
from .generic import Generic
class Zsh(Generic):
def app_alias(self, fuck):
alias = "alias {0}='TF_ALIAS={0} PYTHONIOENCODING=utf-8" \
def app_alias(self, alias_name):
alias = "alias {0}='TF_ALIAS={0}" \
" PYTHONIOENCODING=utf-8" \
' TF_SHELL_ALIASES=$(alias)' \
" TF_CMD=$(thefuck $(fc -ln -1 | tail -n 1)) &&" \
" eval $TF_CMD".format(fuck)
" eval $TF_CMD".format(alias_name)
if settings.alter_history:
return alias + " && print -s $TF_CMD'"
@ -24,13 +25,10 @@ class Zsh(Generic):
return name, value
@memoize
@cache('.zshrc')
def get_aliases(self):
proc = Popen(['zsh', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL)
return dict(
self._parse_alias(alias)
for alias in proc.stdout.read().decode('utf-8').split('\n')
if alias and '=' in alias)
raw_aliases = os.environ['TF_SHELL_ALIASES'].split('\n')
return dict(self._parse_alias(alias)
for alias in raw_aliases if alias and '=' in alias)
def _get_history_file_name(self):
return os.environ.get("HISTFILE",