diff --git a/README.md b/README.md index 81820354..9ed9ab37 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,7 @@ following rules are enabled by default: * `tmux` – fixes `tmux` commands; * `unknown_command` – fixes hadoop hdfs-style "unknown command", for example adds missing '-' to the command on `hdfs dfs ls`; * `unsudo` – removes `sudo` from previous command if a process refuses to run on superuser privilege. +* `upper_to_lower_case` – replaces the uppercase letters with lowercase, so the command is correct; * `vagrant_up` – starts up the vagrant instance; * `whois` – fixes `whois` command; * `workon_doesnt_exists` – fixes `virtualenvwrapper` env name os suggests to create new. diff --git a/tests/rules/test_upper_to_lower_case.py b/tests/rules/test_upper_to_lower_case.py new file mode 100644 index 00000000..d873c523 --- /dev/null +++ b/tests/rules/test_upper_to_lower_case.py @@ -0,0 +1,44 @@ +import pytest + +from thefuck.rules.upper_to_lower_case import match, get_new_command +from thefuck.types import Command + + + +@pytest.mark.parametrize( + "script, output", + [ + ("LS", "command not found"), + ("LS -A", "command not found"), + ], +) +def test_match(script, output): + assert match(Command(script, output)) + + +@pytest.mark.parametrize( + "script, output", + [ + ("ls", ""), + ("cd thefuck", ""), + ("mv tests testing", ""), + ("git add .", ""), + ], +) +def test_not_match(script, output): + assert not match(Command(script, output)) + + +@pytest.mark.parametrize( + "script, output, new_command", + [ + ("LS", "command not found", "ls"), + ("CD TESTS", "command not found", "cd tests"), + ("CAT README.MD", "command not found", "cat readme.md"), + ("GIT ADD .", "command not found", "git add ."), + ("GIT ADD .", "command not found", "git add ."), + ("MV TESTS TESTING", "command not found", "mv tests testing"), + ], +) +def test_get_new_command(script, output, new_command): + assert get_new_command(Command(script, output)) == new_command diff --git a/thefuck/rules/upper_to_lower_case.py b/thefuck/rules/upper_to_lower_case.py new file mode 100644 index 00000000..afdad5dd --- /dev/null +++ b/thefuck/rules/upper_to_lower_case.py @@ -0,0 +1,21 @@ +from thefuck.utils import get_all_executables, which + +# this rule is activated when the typed command is +# in uppercase letters and if the command is not +# executed. However in order to activate this rule +# it is necessary the first word of the whole command +# to be valid. +def match(command): + return (command.script.isupper() + and not which(command.script_parts[0]) + and ('not found' in command.output + or 'is not recognized as' in command.output) + and (command.script_parts[0].lower() in get_all_executables())) + +# returns the same command in lowercase letters +def get_new_command(cmd): + return cmd.script.lower() + + +requires_output = False +priority = 100 \ No newline at end of file