mirror of
https://github.com/nvbn/thefuck.git
synced 2025-11-07 18:42:07 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b1f078e27 | ||
|
|
a47e84fa6b | ||
|
|
bcab700215 | ||
|
|
4fb99fd7a8 | ||
|
|
bb5f6bb705 | ||
|
|
d92765d5df | ||
|
|
d8de5cfd20 | ||
|
|
d73b14ce4b | ||
|
|
04b83cf7e8 |
@@ -161,11 +161,13 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
|||||||
* `git_checkout` – fixes branch name or creates new branch;
|
* `git_checkout` – fixes branch name or creates new branch;
|
||||||
* `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output;
|
* `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output;
|
||||||
* `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`);
|
* `git_fix_stash` – fixes `git stash` commands (misspelled subcommand and missing `save`);
|
||||||
|
* `git_help_aliased` – fixes `git help <alias>` commands replacing <alias> with the aliased command;
|
||||||
* `git_not_command` – fixes wrong git commands like `git brnch`;
|
* `git_not_command` – fixes wrong git commands like `git brnch`;
|
||||||
* `git_pull` – sets upstream before executing previous `git pull`;
|
* `git_pull` – sets upstream before executing previous `git pull`;
|
||||||
* `git_pull_clone` – clones instead of pulling when the repo does not exist;
|
* `git_pull_clone` – clones instead of pulling when the repo does not exist;
|
||||||
* `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`;
|
* `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`;
|
||||||
* `git_push_pull` – runs `git pull` when `push` was rejected;
|
* `git_push_pull` – runs `git pull` when `push` was rejected;
|
||||||
|
* `git_remote_seturl_add` – runs `git remote add` when `git remote set_url` on nonexistant remote;
|
||||||
* `git_stash` – stashes you local modifications before rebasing or switching branch;
|
* `git_stash` – stashes you local modifications before rebasing or switching branch;
|
||||||
* `git_two_dashes` – adds a missing dash to commands like `git commit -amend` or `git rebase -continue`;
|
* `git_two_dashes` – adds a missing dash to commands like `git commit -amend` or `git rebase -continue`;
|
||||||
* `go_run` – appends `.go` extension when compiling/running Go programs;
|
* `go_run` – appends `.go` extension when compiling/running Go programs;
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -26,7 +26,7 @@ elif (3, 0) < version < (3, 3):
|
|||||||
' ({}.{} detected).'.format(*version))
|
' ({}.{} detected).'.format(*version))
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
VERSION = '3.4'
|
VERSION = '3.5'
|
||||||
|
|
||||||
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'],
|
||||||
|
|||||||
24
tests/rules/test_git_help_aliased.py
Normal file
24
tests/rules/test_git_help_aliased.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import pytest
|
||||||
|
from thefuck.rules.git_help_aliased import match, get_new_command
|
||||||
|
from tests.utils import Command
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('script, stdout', [
|
||||||
|
('git help st', "`git st' is aliased to `status'"),
|
||||||
|
('git help ds', "`git ds' is aliased to `diff --staged'")])
|
||||||
|
def test_match(script, stdout):
|
||||||
|
assert match(Command(script=script, stdout=stdout))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('script, stdout', [
|
||||||
|
('git help status', "GIT-STATUS(1)...Git Manual...GIT-STATUS(1)"),
|
||||||
|
('git help diff', "GIT-DIFF(1)...Git Manual...GIT-DIFF(1)")])
|
||||||
|
def test_not_match(script, stdout):
|
||||||
|
assert not match(Command(script=script, stdout=stdout))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('script, stdout, new_command', [
|
||||||
|
('git help st', "`git st' is aliased to `status'", 'git help status'),
|
||||||
|
('git help ds', "`git ds' is aliased to `diff --staged'", 'git help diff')])
|
||||||
|
def test_get_new_command(script, stdout, new_command):
|
||||||
|
assert get_new_command(Command(script=script, stdout=stdout)) == new_command
|
||||||
26
tests/rules/test_git_remote_seturl_add.py
Normal file
26
tests/rules/test_git_remote_seturl_add.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import pytest
|
||||||
|
from thefuck.rules.git_remote_seturl_add import match, get_new_command
|
||||||
|
from tests.utils import Command
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command', [
|
||||||
|
Command(script='git remote set-url origin url', stderr="fatal: No such remote")])
|
||||||
|
def test_match(command):
|
||||||
|
assert match(command)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command', [
|
||||||
|
Command('git remote set-url origin url', stderr=""),
|
||||||
|
Command('git remote add origin url'),
|
||||||
|
Command('git remote remove origin'),
|
||||||
|
Command('git remote prune origin'),
|
||||||
|
Command('git remote set-branches origin branch')
|
||||||
|
])
|
||||||
|
def test_not_match(command):
|
||||||
|
assert not match(command)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command, new_command', [
|
||||||
|
(Command('git remote set-url origin git@github.com:nvbn/thefuck.git'),
|
||||||
|
'git remote add origin git@github.com:nvbn/thefuck.git')])
|
||||||
|
def test_get_new_command(command, new_command):
|
||||||
|
assert get_new_command(command) == new_command
|
||||||
@@ -46,6 +46,13 @@ class TestBash(object):
|
|||||||
assert 'TF_ALIAS=fuck' in shell.app_alias('fuck')
|
assert 'TF_ALIAS=fuck' in shell.app_alias('fuck')
|
||||||
assert 'PYTHONIOENCODING=utf-8' in shell.app_alias('fuck')
|
assert 'PYTHONIOENCODING=utf-8' in shell.app_alias('fuck')
|
||||||
|
|
||||||
|
def test_app_alias_variables_correctly_set(self, shell):
|
||||||
|
alias = shell.app_alias('fuck')
|
||||||
|
assert "alias fuck='TF_CMD=$(TF_ALIAS" in alias
|
||||||
|
assert '$(TF_ALIAS=fuck PYTHONIOENCODING' in alias
|
||||||
|
assert 'PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES' in alias
|
||||||
|
assert 'ALIASES=$(alias) thefuck' in alias
|
||||||
|
|
||||||
def test_get_history(self, history_lines, shell):
|
def test_get_history(self, history_lines, shell):
|
||||||
history_lines(['ls', 'rm'])
|
history_lines(['ls', 'rm'])
|
||||||
assert list(shell.get_history()) == ['ls', 'rm']
|
assert list(shell.get_history()) == ['ls', 'rm']
|
||||||
|
|||||||
@@ -45,6 +45,13 @@ class TestZsh(object):
|
|||||||
assert 'thefuck' in shell.app_alias('fuck')
|
assert 'thefuck' in shell.app_alias('fuck')
|
||||||
assert 'PYTHONIOENCODING' in shell.app_alias('fuck')
|
assert 'PYTHONIOENCODING' in shell.app_alias('fuck')
|
||||||
|
|
||||||
|
def test_app_alias_variables_correctly_set(self, shell):
|
||||||
|
alias = shell.app_alias('fuck')
|
||||||
|
assert "alias fuck='TF_CMD=$(TF_ALIAS" in alias
|
||||||
|
assert '$(TF_ALIAS=fuck PYTHONIOENCODING' in alias
|
||||||
|
assert 'PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES' in alias
|
||||||
|
assert 'ALIASES=$(alias) thefuck' in alias
|
||||||
|
|
||||||
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'])
|
||||||
assert list(shell.get_history()) == ['ls', 'rm']
|
assert list(shell.get_history()) == ['ls', 'rm']
|
||||||
|
|||||||
12
thefuck/rules/git_help_aliased.py
Normal file
12
thefuck/rules/git_help_aliased.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from thefuck.specific.git import git_support
|
||||||
|
|
||||||
|
|
||||||
|
@git_support
|
||||||
|
def match(command):
|
||||||
|
return 'help' in command.script and ' is aliased to ' in command.stdout
|
||||||
|
|
||||||
|
|
||||||
|
@git_support
|
||||||
|
def get_new_command(command):
|
||||||
|
aliased = command.stdout.split('`', 2)[2].split("'", 1)[0].split(' ', 1)[0]
|
||||||
|
return 'git help {}'.format(aliased)
|
||||||
14
thefuck/rules/git_remote_seturl_add.py
Normal file
14
thefuck/rules/git_remote_seturl_add.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from thefuck.utils import replace_argument
|
||||||
|
from thefuck.specific.git import git_support
|
||||||
|
|
||||||
|
|
||||||
|
@git_support
|
||||||
|
def match(command):
|
||||||
|
return ('set-url' in command.script and 'fatal: No such remote' in command.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_command(command):
|
||||||
|
return replace_argument(command.script, 'set-url', 'add')
|
||||||
|
|
||||||
|
|
||||||
|
enabled_by_default = True
|
||||||
@@ -6,9 +6,11 @@ from .generic import Generic
|
|||||||
|
|
||||||
class Bash(Generic):
|
class Bash(Generic):
|
||||||
def app_alias(self, fuck):
|
def app_alias(self, fuck):
|
||||||
alias = "TF_ALIAS={0}" \
|
# It is VERY important to have the variables declared WITHIN the alias
|
||||||
" alias {0}='PYTHONIOENCODING=utf-8" \
|
alias = "alias {0}='TF_CMD=$(TF_ALIAS={0}" \
|
||||||
" TF_CMD=$(TF_SHELL_ALIASES=$(alias) thefuck $(fc -ln -1)) && " \
|
" PYTHONIOENCODING=utf-8" \
|
||||||
|
" TF_SHELL_ALIASES=$(alias)" \
|
||||||
|
" thefuck $(fc -ln -1)) &&" \
|
||||||
" eval $TF_CMD".format(fuck)
|
" eval $TF_CMD".format(fuck)
|
||||||
|
|
||||||
if settings.alter_history:
|
if settings.alter_history:
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class Fish(Generic):
|
|||||||
return ['cd', 'grep', 'ls', 'man', 'open']
|
return ['cd', 'grep', 'ls', 'man', 'open']
|
||||||
|
|
||||||
def app_alias(self, fuck):
|
def app_alias(self, fuck):
|
||||||
|
# It is VERY important to have the variables declared WITHIN the alias
|
||||||
return ('function {0} -d "Correct your previous console command"\n'
|
return ('function {0} -d "Correct your previous console command"\n'
|
||||||
' set -l fucked_up_command $history[1]\n'
|
' set -l fucked_up_command $history[1]\n'
|
||||||
' env TF_ALIAS={0} PYTHONIOENCODING=utf-8'
|
' env TF_ALIAS={0} PYTHONIOENCODING=utf-8'
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ from .generic import Generic
|
|||||||
|
|
||||||
class Zsh(Generic):
|
class Zsh(Generic):
|
||||||
def app_alias(self, alias_name):
|
def app_alias(self, alias_name):
|
||||||
alias = "alias {0}='TF_ALIAS={0}" \
|
# It is VERY important to have the variables declared WITHIN the alias
|
||||||
|
alias = "alias {0}='TF_CMD=$(TF_ALIAS={0}" \
|
||||||
" PYTHONIOENCODING=utf-8" \
|
" PYTHONIOENCODING=utf-8" \
|
||||||
' TF_SHELL_ALIASES=$(alias)' \
|
" TF_SHELL_ALIASES=$(alias)" \
|
||||||
" TF_CMD=$(thefuck $(fc -ln -1 | tail -n 1)) &&" \
|
" thefuck $(fc -ln -1 | tail -n 1)) &&" \
|
||||||
" eval $TF_CMD".format(alias_name)
|
" eval $TF_CMD".format(alias_name)
|
||||||
|
|
||||||
if settings.alter_history:
|
if settings.alter_history:
|
||||||
|
|||||||
@@ -282,5 +282,5 @@ class CorrectedCommand(object):
|
|||||||
compatibility_call(self.side_effect, old_cmd, self.script)
|
compatibility_call(self.side_effect, old_cmd, self.script)
|
||||||
# This depends on correct setting of PYTHONIOENCODING by the alias:
|
# This depends on correct setting of PYTHONIOENCODING by the alias:
|
||||||
logs.debug(u'PYTHONIOENCODING: {}'.format(
|
logs.debug(u'PYTHONIOENCODING: {}'.format(
|
||||||
os.environ.get('PYTHONIOENCODING', '>-not-set-<')))
|
os.environ.get('PYTHONIOENCODING', '!!not-set!!')))
|
||||||
print(self.script)
|
print(self.script)
|
||||||
|
|||||||
@@ -228,8 +228,8 @@ def cache(*depends_on):
|
|||||||
value = fn(*args, **kwargs)
|
value = fn(*args, **kwargs)
|
||||||
db[key] = {'etag': etag, 'value': value}
|
db[key] = {'etag': etag, 'value': value}
|
||||||
return value
|
return value
|
||||||
except shelve_open_error:
|
except (shelve_open_error, ImportError):
|
||||||
# Caused when going from Python 2 to Python 3 and vice-versa
|
# Caused when switching between Python versions
|
||||||
warn("Removing possibly out-dated cache")
|
warn("Removing possibly out-dated cache")
|
||||||
os.remove(cache_path)
|
os.remove(cache_path)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user