mirror of
https://github.com/nvbn/thefuck.git
synced 2025-11-01 15:42:06 +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
|
||||
sudo: false
|
||||
python:
|
||||
- "3.5"
|
||||
- "3.4"
|
||||
- "3.3"
|
||||
- "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_no_command` – fixes wrongs commands like `cargo buid`;
|
||||
* `cd_correction` – spellchecks and correct failed cd commands;
|
||||
* `cd_mkdir` – creates directories before cd'ing into them;
|
||||
* `cd_correction` – spellchecks and correct failed cd commands, when it's not possible
|
||||
creates directories before cd'ing into them;
|
||||
* `cd_parent` – changes `cd..` to `cd ..`;
|
||||
* `composer_not_command` – fixes composer command name;
|
||||
* `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))
|
||||
sys.exit(-1)
|
||||
|
||||
VERSION = '3.0'
|
||||
VERSION = '3.1'
|
||||
|
||||
install_requires = ['psutil', 'colorama', 'six', 'decorator']
|
||||
extras_require = {':python_version<"3.4"': ['pathlib']}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@ def test_match(wrong):
|
||||
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', [
|
||||
('git stash opp', 'git stash pop'),
|
||||
('git stash Some message', 'git stash save Some message'),
|
||||
|
||||
@@ -59,9 +59,11 @@ def how_to_configure_alias():
|
||||
def main():
|
||||
parser = ArgumentParser(prog='thefuck')
|
||||
version = get_installation_info().version
|
||||
parser.add_argument('-v', '--version',
|
||||
action='version',
|
||||
version='%(prog)s {}'.format(version))
|
||||
parser.add_argument(
|
||||
'-v', '--version',
|
||||
action='version',
|
||||
version='The Fuck {} using Python {}'.format(
|
||||
version, sys.version.split()[0]))
|
||||
parser.add_argument('-a', '--alias',
|
||||
action='store_true',
|
||||
help='[custom-alias-name] prints alias for current shell')
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
import os
|
||||
from difflib import get_close_matches
|
||||
import re
|
||||
from thefuck.specific.sudo import sudo_support
|
||||
from thefuck.rules import cd_mkdir
|
||||
from thefuck.utils import for_app
|
||||
from thefuck import shells
|
||||
|
||||
__author__ = "mmussomele"
|
||||
|
||||
@@ -43,11 +44,13 @@ def get_new_command(command):
|
||||
elif directory == "..":
|
||||
cwd = os.path.split(cwd)[0]
|
||||
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:
|
||||
cwd = os.path.join(cwd, best_matches[0])
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
def match(command):
|
||||
return (command.script.split()[1] == 'stash'
|
||||
and 'usage:' in command.stderr)
|
||||
splited_script = command.script.split()
|
||||
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)
|
||||
stash_commands = (
|
||||
|
||||
@@ -134,7 +134,7 @@ class Fish(Generic):
|
||||
" set -l fucked_up_command $history[1]\n"
|
||||
" thefuck $fucked_up_command > $eval_script\n"
|
||||
" . $eval_script\n"
|
||||
" rm $eval_script\n"
|
||||
" /bin/rm $eval_script\n"
|
||||
" if test $exit_code -ne 0\n"
|
||||
" history --delete $fucked_up_command\n"
|
||||
" end\n"
|
||||
|
||||
@@ -44,9 +44,9 @@ def read_actions():
|
||||
buffer.append(ch)
|
||||
buffer = buffer[-3:]
|
||||
|
||||
if buffer == ['\x1b', '[', 'A']: # ↑
|
||||
if buffer == ['\x1b', '[', 'A'] or ch == 'k': # ↑
|
||||
yield PREVIOUS
|
||||
elif buffer == ['\x1b', '[', 'B']: # ↓
|
||||
elif buffer == ['\x1b', '[', 'B'] or ch == 'j': # ↓
|
||||
yield NEXT
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user