1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-19 12:24:29 +00:00

Merge branch 'easy-install' of https://github.com/mcarton/thefuck into mcarton-easy-install

This commit is contained in:
nvbn 2015-07-20 21:06:21 +03:00
commit a849b65352
3 changed files with 45 additions and 52 deletions

View File

@ -1,7 +1,5 @@
# The Fuck [![Build Status](https://travis-ci.org/nvbn/thefuck.svg)](https://travis-ci.org/nvbn/thefuck) # The Fuck [![Build Status](https://travis-ci.org/nvbn/thefuck.svg)](https://travis-ci.org/nvbn/thefuck)
**Aliases changed in 1.34.**
Magnificent app which corrects your previous console command, Magnificent app which corrects your previous console command,
inspired by a [@liamosaur](https://twitter.com/liamosaur/) inspired by a [@liamosaur](https://twitter.com/liamosaur/)
[tweet](https://twitter.com/liamosaur/status/506975850596536320). [tweet](https://twitter.com/liamosaur/status/506975850596536320).
@ -106,29 +104,12 @@ sudo pip install thefuck
[Or using an OS package manager (OS X, Ubuntu, Arch).](https://github.com/nvbn/thefuck/wiki/Installation) [Or using an OS package manager (OS X, Ubuntu, Arch).](https://github.com/nvbn/thefuck/wiki/Installation)
And add to the `.bashrc` or `.bash_profile`(for OSX): You should place this command in your `.bash_profile` or other startup script:
```bash ```bash
alias fuck='eval $(thefuck $(fc -ln -1)); history -r' eval "$(thefuck-alias)"
# You can use whatever you want as an alias, like for Mondays: # You can use whatever you want as an alias, like for Mondays:
alias FUCK='fuck' eval "$(thefuck-alias FUCK)"
```
Or in your `.zshrc`:
```bash
alias fuck='eval $(thefuck $(fc -ln -1 | tail -n 1)); fc -R'
```
If you are using `tcsh`:
```tcsh
alias fuck 'set fucked_cmd=`history -h 2 | head -n 1` && eval `thefuck ${fucked_cmd}`'
```
Alternatively, you can redirect the output of `thefuck-alias`:
```bash
thefuck-alias >> ~/.bashrc
``` ```
[Or in your shell config (Bash, Zsh, Fish, Powershell).](https://github.com/nvbn/thefuck/wiki/Shell-aliases) [Or in your shell config (Bash, Zsh, Fish, Powershell).](https://github.com/nvbn/thefuck/wiki/Shell-aliases)
@ -143,6 +124,8 @@ To make them available immediately, run `source ~/.bashrc` (or your shell config
sudo pip install thefuck --upgrade sudo pip install thefuck --upgrade
``` ```
**Aliases changed in 1.34.**
## How it works ## How it works
The Fuck tries to match a rule for the previous command, creates a new command The Fuck tries to match a rule for the previous command, creates a new command

View File

@ -44,9 +44,10 @@ class TestGeneric(object):
assert shell.get_aliases() == {} assert shell.get_aliases() == {}
def test_app_alias(self, shell): def test_app_alias(self, shell):
assert 'alias fuck' in shell.app_alias() assert 'alias fuck' in shell.app_alias('fuck')
assert 'thefuck' in shell.app_alias() assert 'alias FUCK' in shell.app_alias('FUCK')
assert 'TF_ALIAS' in shell.app_alias() assert 'thefuck' in shell.app_alias('fuck')
assert 'TF_ALIAS' in shell.app_alias('fuck')
def test_get_history(self, history_lines, shell): def test_get_history(self, history_lines, shell):
history_lines(['ls', 'rm']) history_lines(['ls', 'rm'])
@ -97,9 +98,10 @@ class TestBash(object):
'll': 'ls -alF'} 'll': 'ls -alF'}
def test_app_alias(self, shell): def test_app_alias(self, shell):
assert 'alias fuck' in shell.app_alias() assert 'alias fuck' in shell.app_alias('fuck')
assert 'thefuck' in shell.app_alias() assert 'alias FUCK' in shell.app_alias('FUCK')
assert 'TF_ALIAS' in shell.app_alias() assert 'thefuck' in shell.app_alias('fuck')
assert 'TF_ALIAS' in shell.app_alias('fuck')
def test_get_history(self, history_lines, shell): def test_get_history(self, history_lines, shell):
history_lines(['ls', 'rm']) history_lines(['ls', 'rm'])
@ -173,9 +175,10 @@ class TestFish(object):
'ruby': 'ruby'} '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('fuck')
assert 'thefuck' in shell.app_alias() assert 'function FUCK' in shell.app_alias('FUCK')
assert 'TF_ALIAS' in shell.app_alias() assert 'thefuck' in shell.app_alias('fuck')
assert 'TF_ALIAS' in shell.app_alias('fuck')
@pytest.mark.usefixtures('isfile') @pytest.mark.usefixtures('isfile')
@ -222,9 +225,10 @@ class TestZsh(object):
'll': 'ls -alF'} 'll': 'ls -alF'}
def test_app_alias(self, shell): def test_app_alias(self, shell):
assert 'alias fuck' in shell.app_alias() assert 'alias fuck' in shell.app_alias('fuck')
assert 'thefuck' in shell.app_alias() assert 'alias FUCK' in shell.app_alias('FUCK')
assert 'TF_ALIAS' in shell.app_alias() assert 'thefuck' in shell.app_alias('fuck')
assert 'TF_ALIAS' in shell.app_alias('fuck')
def test_get_history(self, history_lines, shell): def test_get_history(self, history_lines, shell):
history_lines([': 1432613911:0;ls', ': 1432613916:0;rm']) history_lines([': 1432613911:0;ls', ': 1432613916:0;rm'])

View File

@ -4,11 +4,12 @@ methods.
""" """
from collections import defaultdict from collections import defaultdict
from psutil import Process
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from time import time from time import time
import os
import io import io
from psutil import Process import os
import sys
from .utils import DEVNULL, memoize from .utils import DEVNULL, memoize
@ -33,8 +34,8 @@ class Generic(object):
"""Prepares command for running in shell.""" """Prepares command for running in shell."""
return command_script return command_script
def app_alias(self): def app_alias(self, fuck):
return "\nalias fuck='TF_ALIAS=fuck eval $(thefuck $(fc -ln -1))'\n" return "alias {0}='TF_ALIAS={0} eval $(thefuck $(fc -ln -1))'".format(fuck)
def _get_history_file_name(self): def _get_history_file_name(self):
return '' return ''
@ -74,9 +75,9 @@ class Generic(object):
class Bash(Generic): class Bash(Generic):
def app_alias(self): def app_alias(self, fuck):
return "\nTF_ALIAS=fuck alias fuck='eval $(thefuck $(fc -ln -1));" \ return "TF_ALIAS={0} alias {0}='eval $(thefuck $(fc -ln -1));" \
" history -r'\n" " history -r'".format(fuck)
def _parse_alias(self, alias): def _parse_alias(self, alias):
name, value = alias.replace('alias ', '', 1).split('=', 1) name, value = alias.replace('alias ', '', 1).split('=', 1)
@ -113,9 +114,9 @@ class Fish(Generic):
else: else:
return ['cd', 'grep', 'ls', 'man', 'open'] return ['cd', 'grep', 'ls', 'man', 'open']
def app_alias(self): def app_alias(self, fuck):
return ("set TF_ALIAS fuck\n" return ("set TF_ALIAS {0}\n"
"function fuck -d 'Correct your previous console command'\n" "function {0} -d 'Correct your previous console command'\n"
" set -l exit_code $status\n" " set -l exit_code $status\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"
@ -126,7 +127,7 @@ class Fish(Generic):
" if test $exit_code -ne 0\n" " if test $exit_code -ne 0\n"
" history --delete $fucked_up_commandd\n" " history --delete $fucked_up_commandd\n"
" end\n" " end\n"
"end") "end").format(fuck)
def get_aliases(self): def get_aliases(self):
overridden = self._get_overridden_aliases() overridden = self._get_overridden_aliases()
@ -158,10 +159,10 @@ class Fish(Generic):
class Zsh(Generic): class Zsh(Generic):
def app_alias(self): def app_alias(self, fuck):
return "\nTF_ALIAS=fuck" \ return "TF_ALIAS={0}" \
" alias fuck='eval $(thefuck $(fc -ln -1 | tail -n 1));" \ " alias {0}='eval $(thefuck $(fc -ln -1 | tail -n 1));" \
" fc -R'\n" " fc -R'".format(fuck)
def _parse_alias(self, alias): def _parse_alias(self, alias):
name, value = alias.split('=', 1) name, value = alias.split('=', 1)
@ -192,8 +193,10 @@ class Zsh(Generic):
class Tcsh(Generic): class Tcsh(Generic):
def app_alias(self): def app_alias(self, fuck):
return "\nalias fuck 'setenv TF_ALIAS fuck && set fucked_cmd=`history -h 2 | head -n 1` && eval `thefuck ${fucked_cmd}`'\n" return ("alias {0} 'setenv TF_ALIAS {0} && "
"set fucked_cmd=`history -h 2 | head -n 1` && "
"eval `thefuck ${fucked_cmd}`'").format(fuck)
def _parse_alias(self, alias): def _parse_alias(self, alias):
name, value = alias.split("\t", 1) name, value = alias.split("\t", 1)
@ -240,7 +243,10 @@ def to_shell(command):
def app_alias(): def app_alias():
print(_get_shell().app_alias()) alias = thefuck_alias()
if len(sys.argv) > 1:
alias = sys.argv[1]
print(_get_shell().app_alias(alias))
def thefuck_alias(): def thefuck_alias():