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

Compare commits

...

12 Commits
1.13 ... 1.14

Author SHA1 Message Date
nvbn
2db0a215b4 Fix fuck when more than one git command available 2015-04-20 21:48:54 +02:00
Vladimir Iakovlev
f6f6e2223c Merge pull request #62 from sjuvekar/master
A special case for 'Permission denied' error msg when trying to execute ...
2015-04-20 18:52:35 +02:00
Vladimir Iakovlev
d86bf8da40 Merge pull request #60 from pcmitsis/patch-1
Update Readme to contain a link to the license
2015-04-20 18:50:09 +02:00
Vladimir Iakovlev
a77ca37be2 Merge pull request #64 from nwinkler/mkdir-p
mkdir -p
2015-04-20 18:49:10 +02:00
Vladimir Iakovlev
3fb7a0c123 Merge pull request #63 from KAMiKAZOW/patch-1
tweet, not twit
2015-04-20 18:48:33 +02:00
Nils Winkler
c0c584b13a mkdir -p
When adding directories using `mkdir`, intermediate directories have to
exist, unless you specify the `-p` option:

    $ mkdir foo/bar/baz
    mkdir: foo/bar: No such file or directory
    $ fuck
    mkdir -p foo/bar/baz
2015-04-20 18:38:03 +02:00
Markus S.
a81d9af621 tweet, not twit 2015-04-20 18:19:34 +02:00
Sudeep Juvekar
1d878243ca A special case for 'Permission denied' error msg when trying to execute a
python scripy.

The script does not have execute permission and/or does not start with !#/usr/...
In that case, pre-pend the command with 'python' keyword.

Change-Id: Idf73ee9cf0a523f51c78672188a457b2fcedc1e6
2015-04-20 12:11:06 -04:00
Sudeep Juvekar
cb31a1f7d0 A special case for 'Permission denied' error msg when trying to execute a
python scripy.

The script does not have execute permission and/or does not start with !#/usr/...
In that case, pre-pend the command with 'python' keyword.

Change-Id: Idf73ee9cf0a523f51c78672188a457b2fcedc1e6
2015-04-20 12:00:08 -04:00
Sudeep Juvekar
17397bf30f A special case for 'Permission denied' error msg when trying to execute a
python scripy.

The script does not have execute permission and/or does not start with !#/usr/...
In that case, pre-pend the command with 'python' keyword.

Change-Id: Idf73ee9cf0a523f51c78672188a457b2fcedc1e6
2015-04-20 11:00:35 -04:00
Sudeep Juvekar
411aea67f7 A special case for 'Permission denied' error msg when trying to execute a
python scripy.

The script does not have execute permission and/or does not start with !#/usr/...
In that case, pre-pend the command with 'python' keyword.

Change-Id: Idf73ee9cf0a523f51c78672188a457b2fcedc1e6
2015-04-20 10:49:39 -04:00
Panagiotis Mitsis
0b0ad0558a Update Readme to contain a link to the license
A small reference to the license from the readme file.
2015-04-20 16:32:50 +02:00
9 changed files with 69 additions and 8 deletions

View File

@@ -1,8 +1,8 @@
# The Fuck [![Build Status](https://travis-ci.org/nvbn/thefuck.svg)](https://travis-ci.org/nvbn/thefuck)
Magnificent app which corrects your previous console command,
inspired by [@liamosaur](https://twitter.com/liamosaur/status/506975850596536320)
twit.
inspired by a [@liamosaur](https://twitter.com/liamosaur/)
[tweet](https://twitter.com/liamosaur/status/506975850596536320).
Few examples:
@@ -190,3 +190,4 @@ py.test
```
## License MIT
Project License can be found [here](LICENSE.md).

View File

@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(name='thefuck',
version=1.13,
version=1.14,
description="Magnificent app which corrects your previous console command",
author='Vladimir Iakovlev',
author_email='nvbn.rm@gmail.com',

View File

@@ -12,17 +12,33 @@ branch
"""
@pytest.fixture
def git_not_command_one_of_this():
return """git: 'st' is not a git command. See 'git --help'.
Did you mean one of these?
status
reset
stage
stash
stats
"""
@pytest.fixture
def git_command():
return "* master"
def test_match(git_not_command, git_command):
def test_match(git_not_command, git_command, git_not_command_one_of_this):
assert match(Command('git brnch', '', git_not_command), None)
assert match(Command('git st', '', git_not_command_one_of_this), None)
assert not match(Command('ls brnch', '', git_not_command), None)
assert not match(Command('git branch', '', git_command), None)
def test_get_new_command(git_not_command):
def test_get_new_command(git_not_command, git_not_command_one_of_this):
assert get_new_command(Command('git brnch', '', git_not_command), None)\
== 'git branch'
assert get_new_command(
Command('git st', '', git_not_command_one_of_this), None) == 'git status'

View File

@@ -0,0 +1,13 @@
from thefuck.main import Command
from thefuck.rules.mkdir_p import match, get_new_command
def test_match():
assert match(Command('mkdir foo/bar/baz', '', 'mkdir: foo/bar: No such file or directory'), None)
assert not match(Command('mkdir foo/bar/baz', '', ''), None)
assert not match(Command('mkdir foo/bar/baz', '', 'foo bar baz'), None)
assert not match(Command('', '', ''), None)
def test_get_new_command():
assert get_new_command(Command('mkdir foo/bar/baz', '', ''), None) == 'mkdir -p foo/bar/baz'

View File

@@ -0,0 +1,9 @@
from thefuck.main import Command
from thefuck.rules.python_command import match, get_new_command
def test_match():
assert match(Command('temp.py', '', 'Permission denied'), None)
assert not match(Command('', '', ''), None)
def test_get_new_command():
assert get_new_command(Command('./test_sudo.py', '', ''), None) == 'python ./test_sudo.py'

View File

@@ -51,7 +51,7 @@ def get_rules(user_dir, settings):
.joinpath('rules')\
.glob('*.py')
user = user_dir.joinpath('rules').glob('*.py')
return [load_rule(rule) for rule in list(bundled) + list(user)
return [load_rule(rule) for rule in sorted(list(bundled)) + list(user)
if rule.name != '__init__.py' and is_rule_enabled(settings, rule)]

View File

@@ -4,13 +4,13 @@ import re
def match(command, settings):
return ('git' in command.script
and " is not a git command. See 'git --help'." in command.stderr
and 'Did you mean this?' in command.stderr)
and 'Did you mean' in command.stderr)
def get_new_command(command, settings):
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
command.stderr)[0]
new_cmd = re.findall(r'Did you mean this\?\n\s*([^\n]*)',
new_cmd = re.findall(r'Did you mean[^\n]*\n\s*([^\n]*)',
command.stderr)[0]
return command.script.replace(broken_cmd, new_cmd, 1)

9
thefuck/rules/mkdir_p.py Normal file
View File

@@ -0,0 +1,9 @@
import re
def match(command, settings):
return ('mkdir' in command.script
and 'No such file or directory' in command.stderr)
def get_new_command(command, settings):
return re.sub('^mkdir (.*)', 'mkdir -p \\1', command.script)

View File

@@ -0,0 +1,13 @@
# add 'python' suffix to the command if
# 1) The script does not have execute permission or
# 2) is interpreted as shell script
def match(command, settings):
toks = command.script.split()
return (len(toks) > 0
and toks[0].endswith('.py')
and ('Permission denied' in command.stderr or
'command not found' in command.stderr))
def get_new_command(command, settings):
return 'python ' + command.script