Skip to content

Commit

Permalink
refact(shells): use an env var TF_ALIAS to keep the name of the alias
Browse files Browse the repository at this point in the history
This environment variable may be used by any rule to decide whether it
matches or not.
  • Loading branch information
scorphus committed Jun 10, 2015
1 parent b986b0d commit c7bbadc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
20 changes: 20 additions & 0 deletions tests/test_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def test_and_(self, shell):
def test_get_aliases(self, shell):
assert shell.get_aliases() == {}

def test_app_alias(self, shell):
assert 'alias fuck' in shell.app_alias()
assert 'thefuck' in shell.app_alias()
assert 'TF_ALIAS' in shell.app_alias()


@pytest.mark.usefixtures('isfile')
class TestBash(object):
Expand Down Expand Up @@ -75,6 +80,11 @@ def test_get_aliases(self, shell):
'la': 'ls -A',
'll': 'ls -alF'}

def test_app_alias(self, shell):
assert 'alias fuck' in shell.app_alias()
assert 'thefuck' in shell.app_alias()
assert 'TF_ALIAS' in shell.app_alias()


@pytest.mark.usefixtures('isfile')
class TestFish(object):
Expand Down Expand Up @@ -124,6 +134,11 @@ def test_get_aliases(self, shell):
'll': 'll',
'math': 'math'}

def test_app_alias(self, shell):
assert 'function fuck' in shell.app_alias()
assert 'thefuck' in shell.app_alias()
assert 'TF_ALIAS' in shell.app_alias()


@pytest.mark.usefixtures('isfile')
class TestZsh(object):
Expand Down Expand Up @@ -167,3 +182,8 @@ def test_get_aliases(self, shell):
'l': 'ls -CF',
'la': 'ls -A',
'll': 'ls -alF'}

def test_app_alias(self, shell):
assert 'alias fuck' in shell.app_alias()
assert 'thefuck' in shell.app_alias()
assert 'TF_ALIAS' in shell.app_alias()
13 changes: 9 additions & 4 deletions thefuck/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def to_shell(self, command_script):
return command_script

def app_alias(self):
return "\nalias fuck='eval $(thefuck $(fc -ln -1))'\n"
return "\nalias fuck='TF_ALIAS=fuck eval $(thefuck $(fc -ln -1))'\n"

def _get_history_file_name(self):
return ''
Expand All @@ -54,7 +54,7 @@ def and_(self, *commands):

class Bash(Generic):
def app_alias(self):
return "\nalias fuck='eval $(thefuck $(fc -ln -1)); history -r'\n"
return "\nalias fuck='TF_ALIAS=fuck eval $(thefuck $(fc -ln -1)); history -r'\n"

def _parse_alias(self, alias):
name, value = alias.replace('alias ', '', 1).split('=', 1)
Expand Down Expand Up @@ -83,6 +83,7 @@ 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 TF_ALIAS fuck\n"
" set -l eval_script"
" (mktemp 2>/dev/null ; or mktemp -t 'thefuck')\n"
" set -l fucked_up_commandd $history[1]\n"
Expand Down Expand Up @@ -125,7 +126,7 @@ def and_(self, *commands):

class Zsh(Generic):
def app_alias(self):
return "\nalias fuck='eval $(thefuck $(fc -ln -1 | tail -n 1)); fc -R'\n"
return "\nalias fuck='TF_ALIAS=fuck eval $(thefuck $(fc -ln -1 | tail -n 1)); fc -R'\n"

def _parse_alias(self, alias):
name, value = alias.split('=', 1)
Expand All @@ -152,7 +153,7 @@ def _get_history_line(self, command_script):

class Tcsh(Generic):
def app_alias(self):
return "\nalias fuck 'set fucked_cmd=`history -h 2 | head -n 1` && eval `thefuck ${fucked_cmd}`'\n"
return "\nalias fuck 'setenv TF_ALIAS fuck && set fucked_cmd=`history -h 2 | head -n 1` && eval `thefuck ${fucked_cmd}`'\n"

def _parse_alias(self, alias):
name, value = alias.split("\t", 1)
Expand Down Expand Up @@ -203,6 +204,10 @@ def app_alias():
print(_get_shell().app_alias())


def thefuck_alias():
return os.environ.get('TF_ALIAS', 'fuck')


def put_to_history(command):
return _get_shell().put_to_history(command)

Expand Down

0 comments on commit c7bbadc

Please sign in to comment.