mirror of
https://github.com/nvbn/thefuck.git
synced 2025-11-02 08:02:04 +00:00
Compare commits
12 Commits
3.0
...
merge-cd-r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0fcc35c227 | ||
|
|
3da26192cb | ||
|
|
11c133523a | ||
|
|
4b3e6a1448 | ||
|
|
09d9f63c98 | ||
|
|
e8883429c6 | ||
|
|
c1b67f2514 | ||
|
|
3d6e7b17db | ||
|
|
75ef866214 | ||
|
|
5021d16cea | ||
|
|
af259846b4 | ||
|
|
213791d3c2 |
@@ -1,6 +1,7 @@
|
|||||||
language: python
|
language: python
|
||||||
sudo: false
|
sudo: false
|
||||||
python:
|
python:
|
||||||
|
- "3.5"
|
||||||
- "3.4"
|
- "3.4"
|
||||||
- "3.3"
|
- "3.3"
|
||||||
- "2.7"
|
- "2.7"
|
||||||
|
|||||||
@@ -141,8 +141,8 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
|||||||
|
|
||||||
* `cargo` – runs `cargo build` instead of `cargo`;
|
* `cargo` – runs `cargo build` instead of `cargo`;
|
||||||
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
* `cargo_no_command` – fixes wrongs commands like `cargo buid`;
|
||||||
* `cd_correction` – spellchecks and correct failed cd commands;
|
* `cd_correction` – spellchecks and correct failed cd commands, when it's not possible
|
||||||
* `cd_mkdir` – creates directories before cd'ing into them;
|
creates directories before cd'ing into them;
|
||||||
* `cd_parent` – changes `cd..` to `cd ..`;
|
* `cd_parent` – changes `cd..` to `cd ..`;
|
||||||
* `composer_not_command` – fixes composer command name;
|
* `composer_not_command` – fixes composer command name;
|
||||||
* `cp_omitting_directory` – adds `-a` when you `cp` directory;
|
* `cp_omitting_directory` – adds `-a` when you `cp` directory;
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -20,7 +20,7 @@ elif (3, 0) < version < (3, 3):
|
|||||||
' ({}.{} detected).'.format(*version))
|
' ({}.{} detected).'.format(*version))
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
VERSION = '3.0'
|
VERSION = '3.1'
|
||||||
|
|
||||||
install_requires = ['psutil', 'colorama', 'six', 'decorator']
|
install_requires = ['psutil', 'colorama', 'six', 'decorator']
|
||||||
extras_require = {':python_version<"3.4"': ['pathlib']}
|
extras_require = {':python_version<"3.4"': ['pathlib']}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from thefuck.rules.cd_mkdir import match, get_new_command
|
from thefuck.rules.cd_correction import match, get_new_command
|
||||||
from tests.utils import Command
|
from tests.utils import Command
|
||||||
|
|
||||||
|
|
||||||
@@ -23,6 +23,10 @@ def test_match(wrong):
|
|||||||
assert match(Command(wrong, stderr=git_stash_err))
|
assert match(Command(wrong, stderr=git_stash_err))
|
||||||
|
|
||||||
|
|
||||||
|
def test_not_match():
|
||||||
|
assert not match(Command("git", stderr=git_stash_err))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('wrong,fixed', [
|
@pytest.mark.parametrize('wrong,fixed', [
|
||||||
('git stash opp', 'git stash pop'),
|
('git stash opp', 'git stash pop'),
|
||||||
('git stash Some message', 'git stash save Some message'),
|
('git stash Some message', 'git stash save Some message'),
|
||||||
|
|||||||
@@ -59,9 +59,11 @@ def how_to_configure_alias():
|
|||||||
def main():
|
def main():
|
||||||
parser = ArgumentParser(prog='thefuck')
|
parser = ArgumentParser(prog='thefuck')
|
||||||
version = get_installation_info().version
|
version = get_installation_info().version
|
||||||
parser.add_argument('-v', '--version',
|
parser.add_argument(
|
||||||
action='version',
|
'-v', '--version',
|
||||||
version='%(prog)s {}'.format(version))
|
action='version',
|
||||||
|
version='The Fuck {} using Python {}'.format(
|
||||||
|
version, sys.version.split()[0]))
|
||||||
parser.add_argument('-a', '--alias',
|
parser.add_argument('-a', '--alias',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='[custom-alias-name] prints alias for current shell')
|
help='[custom-alias-name] prints alias for current shell')
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from difflib import get_close_matches
|
from difflib import get_close_matches
|
||||||
|
import re
|
||||||
from thefuck.specific.sudo import sudo_support
|
from thefuck.specific.sudo import sudo_support
|
||||||
from thefuck.rules import cd_mkdir
|
|
||||||
from thefuck.utils import for_app
|
from thefuck.utils import for_app
|
||||||
|
from thefuck import shells
|
||||||
|
|
||||||
__author__ = "mmussomele"
|
__author__ = "mmussomele"
|
||||||
|
|
||||||
@@ -43,11 +44,13 @@ def get_new_command(command):
|
|||||||
elif directory == "..":
|
elif directory == "..":
|
||||||
cwd = os.path.split(cwd)[0]
|
cwd = os.path.split(cwd)[0]
|
||||||
continue
|
continue
|
||||||
best_matches = get_close_matches(directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF)
|
best_matches = get_close_matches(
|
||||||
|
directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF)
|
||||||
if best_matches:
|
if best_matches:
|
||||||
cwd = os.path.join(cwd, best_matches[0])
|
cwd = os.path.join(cwd, best_matches[0])
|
||||||
else:
|
else:
|
||||||
return cd_mkdir.get_new_command(command)
|
repl = shells.and_('mkdir -p \\1', 'cd \\1')
|
||||||
|
return re.sub(r'^cd (.*)', repl, command.script)
|
||||||
return 'cd "{0}"'.format(cwd)
|
return 'cd "{0}"'.format(cwd)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import re
|
|
||||||
from thefuck import shells
|
|
||||||
from thefuck.utils import for_app
|
|
||||||
from thefuck.specific.sudo import sudo_support
|
|
||||||
|
|
||||||
|
|
||||||
@sudo_support
|
|
||||||
@for_app('cd')
|
|
||||||
def match(command):
|
|
||||||
return (('no such file or directory' in command.stderr.lower()
|
|
||||||
or 'cd: can\'t cd to' in command.stderr.lower()))
|
|
||||||
|
|
||||||
|
|
||||||
@sudo_support
|
|
||||||
def get_new_command(command):
|
|
||||||
repl = shells.and_('mkdir -p \\1', 'cd \\1')
|
|
||||||
return re.sub(r'^cd (.*)', repl, command.script)
|
|
||||||
@@ -5,8 +5,12 @@ from thefuck.specific.git import git_support
|
|||||||
|
|
||||||
@git_support
|
@git_support
|
||||||
def match(command):
|
def match(command):
|
||||||
return (command.script.split()[1] == 'stash'
|
splited_script = command.script.split()
|
||||||
and 'usage:' in command.stderr)
|
if len(splited_script) > 1:
|
||||||
|
return (splited_script[1] == 'stash'
|
||||||
|
and 'usage:' in command.stderr)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
# git's output here is too complicated to be parsed (see the test file)
|
# git's output here is too complicated to be parsed (see the test file)
|
||||||
stash_commands = (
|
stash_commands = (
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class Fish(Generic):
|
|||||||
" set -l fucked_up_command $history[1]\n"
|
" set -l fucked_up_command $history[1]\n"
|
||||||
" thefuck $fucked_up_command > $eval_script\n"
|
" thefuck $fucked_up_command > $eval_script\n"
|
||||||
" . $eval_script\n"
|
" . $eval_script\n"
|
||||||
" rm $eval_script\n"
|
" /bin/rm $eval_script\n"
|
||||||
" if test $exit_code -ne 0\n"
|
" if test $exit_code -ne 0\n"
|
||||||
" history --delete $fucked_up_command\n"
|
" history --delete $fucked_up_command\n"
|
||||||
" end\n"
|
" end\n"
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ def read_actions():
|
|||||||
buffer.append(ch)
|
buffer.append(ch)
|
||||||
buffer = buffer[-3:]
|
buffer = buffer[-3:]
|
||||||
|
|
||||||
if buffer == ['\x1b', '[', 'A']: # ↑
|
if buffer == ['\x1b', '[', 'A'] or ch == 'k': # ↑
|
||||||
yield PREVIOUS
|
yield PREVIOUS
|
||||||
elif buffer == ['\x1b', '[', 'B']: # ↓
|
elif buffer == ['\x1b', '[', 'B'] or ch == 'j': # ↓
|
||||||
yield NEXT
|
yield NEXT
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user