From f94e95cbb209face0a41d5eab45b633c9910f6b1 Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 16:56:44 +0800 Subject: [PATCH 01/16] fix setup.py and fastentrypoints.py --- fastentrypoints.py | 15 ++++++-- setup.py | 85 +++++++++++++++++++++++++++++++--------------- 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/fastentrypoints.py b/fastentrypoints.py index 7bddb46..c06ad48 100644 --- a/fastentrypoints.py +++ b/fastentrypoints.py @@ -23,6 +23,7 @@ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ''' Monkey patch setuptools to write faster console_scripts with this format: @@ -35,8 +36,11 @@ This is better. (c) 2016, Aaron Christianson http://github.com/ninjaaron/fast-entry_points ''' + from setuptools.command import easy_install import re + + TEMPLATE = r'''\ # -*- coding: utf-8 -*- # EASY-INSTALL-ENTRY-SCRIPT: '{3}','{4}','{5}' @@ -60,15 +64,20 @@ def get_args(cls, dist, header=None): if header is None: header = cls.get_header() spec = str(dist.as_requirement()) - for type_ in 'console', 'gui': + for type_ in ['console', 'gui']: group = type_ + '_scripts' for name, ep in dist.get_entry_map(group).items(): # ensure_safe_name if re.search(r'[\\/]', name): raise ValueError("Path separators not allowed in script names") script_text = TEMPLATE.format( - ep.module_name, ep.attrs[0], '.'.join(ep.attrs), - spec, group, name) + ep.module_name, + ep.attrs[0], + '.'.join(ep.attrs), + spec, + group, + name + ) args = cls._get_script_args(type_, name, header, script_text) for res in args: yield res diff --git a/setup.py b/setup.py index 1105aef..5e68460 100755 --- a/setup.py +++ b/setup.py @@ -33,38 +33,67 @@ elif (3, 0) < version < (3, 5): VERSION = '3.32' -install_requires = ['psutil', 'colorama', 'six'] -extras_require = {':python_version<"3.4"': ['pathlib2'], - ':python_version<"3.3"': ['backports.shutil_get_terminal_size'], - ':python_version<="2.7"': ['decorator<5', 'pyte<0.8.1'], - ':python_version>"2.7"': ['decorator', 'pyte'], - ":sys_platform=='win32'": ['win_unicode_console']} +install_requires = [ + 'psutil', + 'colorama', + 'six' +] + +extras_require = { + ':python_version<"3.4"': ['pathlib2'], + ':python_version<"3.3"': ['backports.shutil_get_terminal_size'], + ':python_version<="2.7"': [ + 'decorator<5', + 'pyte<0.8.1' + ], + ':python_version>"2.7"': [ + 'decorator', + 'pyte' + ], + ":sys_platform=='win32'": [ + 'win_unicode_console' + ] +} if sys.platform == "win32": - scripts = ['scripts\\fuck.bat', 'scripts\\fuck.ps1'] + scripts = [ + 'scripts\\fuck.bat', + 'scripts\\fuck.ps1' + ] entry_points = {'console_scripts': [ - 'thefuck = thefuck.entrypoints.main:main', - 'thefuck_firstuse = thefuck.entrypoints.not_configured:main']} + 'thefuck = thefuck.entrypoints.main:main', + 'thefuck_firstuse = thefuck.entrypoints.not_configured:main' + ]} else: scripts = [] entry_points = {'console_scripts': [ - 'thefuck = thefuck.entrypoints.main:main', - 'fuck = thefuck.entrypoints.not_configured:main']} + 'thefuck = thefuck.entrypoints.main:main', + 'fuck = thefuck.entrypoints.not_configured:main' + ]} -setup(name='thefuck', - version=VERSION, - description="Magnificent app which corrects your previous console command", - long_description=long_description, - author='Vladimir Iakovlev', - author_email='nvbn.rm@gmail.com', - url='https://github.com/nvbn/thefuck', - license='MIT', - packages=find_packages(exclude=['ez_setup', 'examples', - 'tests', 'tests.*', 'release']), - include_package_data=True, - zip_safe=False, - python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', - install_requires=install_requires, - extras_require=extras_require, - scripts=scripts, - entry_points=entry_points) +package_exclude = [ + 'ez_setup', + 'examples', + 'tests', + 'tests.*', + 'release' +] + +setup( + name = 'thefuck', + version = VERSION, + description = "Magnificent app which corrects your previous console command", + long_description = long_description, + author = 'Vladimir Iakovlev', + author_email = 'nvbn.rm@gmail.com', + url = 'https://github.com/nvbn/thefuck', + license = 'MIT', + packages = find_packages(exclude = package_exclude), + include_package_data = True, + zip_safe = False, + python_requires = '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', + install_requires = install_requires, + extras_require = extras_require, + scripts = scripts, + entry_points = entry_points +) From 5bf7e58a3b6eac615ca52a9d1cb65a05eae98b73 Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 17:10:16 +0800 Subject: [PATCH 02/16] fix test_utils.py --- tests/test_utils.py | 107 +++++++++++++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 36 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 95f92bc..9689d06 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -10,10 +10,18 @@ from thefuck.utils import default_settings, \ from thefuck.types import Command -@pytest.mark.parametrize('override, old, new', [ - ({'key': 'val'}, {}, {'key': 'val'}), - ({'key': 'new-val'}, {'key': 'val'}, {'key': 'val'}), - ({'key': 'new-val', 'unset': 'unset'}, {'key': 'val'}, {'key': 'val', 'unset': 'unset'})]) +@pytest.mark.parametrize( + 'override, old, new', + [ + ({'key': 'val'}, {}, {'key': 'val'}), + ({'key': 'new-val'}, {'key': 'val'}, {'key': 'val'}), + ( + {'key': 'new-val', 'unset': 'unset'}, + {'key': 'val'}, + {'key': 'val', 'unset': 'unset'} + ) + ] +) def test_default_settings(settings, override, old, new): settings.clear() settings.update(old) @@ -46,7 +54,8 @@ class TestGetClosest(object): assert 'status' == get_closest('st', ['status', 'reset']) def test_without_fallback(self): - assert get_closest('st', ['status', 'reset'], + assert get_closest('st', + ['status', 'reset'], fallback_to_first=False) is None @@ -115,31 +124,55 @@ def test_replace_argument(args, result): assert replace_argument(*args) == result -@pytest.mark.parametrize('stderr, result', [ - (("git: 'cone' is not a git command. See 'git --help'.\n" - '\n' - 'Did you mean one of these?\n' - '\tclone'), ['clone']), - (("git: 're' is not a git command. See 'git --help'.\n" - '\n' - 'Did you mean one of these?\n' - '\trebase\n' - '\treset\n' - '\tgrep\n' - '\trm'), ['rebase', 'reset', 'grep', 'rm']), - (('tsuru: "target" is not a tsuru command. See "tsuru help".\n' - '\n' - 'Did you mean one of these?\n' - '\tservice-add\n' - '\tservice-bind\n' - '\tservice-doc\n' - '\tservice-info\n' - '\tservice-list\n' - '\tservice-remove\n' - '\tservice-status\n' - '\tservice-unbind'), ['service-add', 'service-bind', 'service-doc', - 'service-info', 'service-list', 'service-remove', - 'service-status', 'service-unbind'])]) +@pytest.mark.parametrize( + 'stderr, result', + [ + ( + ( + "git: 'cone' is not a git command. See 'git --help'.\n" + '\n' + 'Did you mean one of these?\n' + '\tclone' + ), + ['clone'] + ), + ( + ( + "git: 're' is not a git command. See 'git --help'.\n" + '\n' + 'Did you mean one of these?\n' + '\trebase\n' + '\treset\n' + '\tgrep\n' + '\trm' + ), + [ + 'rebase', 'reset', + 'grep', 'rm' + ] + ), + ( + ( + 'tsuru: "target" is not a tsuru command. See "tsuru help".\n' + '\n' + 'Did you mean one of these?\n' + '\tservice-add\n' + '\tservice-bind\n' + '\tservice-doc\n' + '\tservice-info\n' + '\tservice-list\n' + '\tservice-remove\n' + '\tservice-status\n' + '\tservice-unbind' + ), + [ + 'service-add', 'service-bind', 'service-doc', + 'service-info', 'service-list', 'service-remove', + 'service-status', 'service-unbind' + ] + ) + ] +) def test_get_all_matched_commands(stderr, result): assert list(get_all_matched_commands(stderr)) == result @@ -265,12 +298,14 @@ class TestGetValidHistoryWithoutCurrent(object): path_mock = mocker.Mock(iterdir=mocker.Mock(return_value=callables)) return mocker.patch('thefuck.utils.Path', return_value=path_mock) - @pytest.mark.parametrize('script, result', [ - ('le cat', ['ls cat', 'diff x', u'café ô']), - ('diff x', ['ls cat', u'café ô']), - ('fuck', ['ls cat', 'diff x', u'café ô']), - (u'cafe ô', ['ls cat', 'diff x', u'café ô']), - ]) + @pytest.mark.parametrize( + 'script, result', [ + ('le cat', ['ls cat', 'diff x', u'café ô']), + ('diff x', ['ls cat', u'café ô']), + ('fuck', ['ls cat', 'diff x', u'café ô']), + (u'cafe ô', ['ls cat', 'diff x', u'café ô']), + ] + ) def test_get_valid_history_without_current(self, script, result): command = Command(script, '') assert get_valid_history_without_current(command) == result From f6c3800dfefd8f12c688bc36c4cbaf732e7490b7 Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 17:12:40 +0800 Subject: [PATCH 03/16] fix utils.py --- thefuck/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/thefuck/utils.py b/thefuck/utils.py index 466e4ba..2670eee 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -327,9 +327,11 @@ def get_valid_history_without_current(command): executables = set(get_all_executables())\ .union(shell.get_builtin_commands()) - return [line for line in _not_corrected(history, tf_alias) - if not line.startswith(tf_alias) and not line == command.script - and line.split(' ')[0] in executables] + return [ + line for line in _not_corrected(history, tf_alias) + if not line.startswith(tf_alias) and not line == command.script + and line.split(' ')[0] in executables + ] def format_raw_script(raw_script): From 6991f14896f81072b579455ec996e78c1c1cc86c Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 17:15:48 +0800 Subject: [PATCH 04/16] fix types.py --- thefuck/types.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/thefuck/types.py b/thefuck/types.py index b3b64c3..ba9a3ae 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -109,22 +109,30 @@ class Rule(object): def __eq__(self, other): if isinstance(other, Rule): - return ((self.name, self.match, self.get_new_command, - self.enabled_by_default, self.side_effect, - self.priority, self.requires_output) - == (other.name, other.match, other.get_new_command, - other.enabled_by_default, other.side_effect, - other.priority, other.requires_output)) + return ( + ( + self.name, self.match, self.get_new_command, + self.enabled_by_default, self.side_effect, + self.priority, self.requires_output + ) == ( + other.name, other.match, other.get_new_command, + other.enabled_by_default, other.side_effect, + other.priority, other.requires_output + ) + ) else: return False def __repr__(self): - return 'Rule(name={}, match={}, get_new_command={}, ' \ - 'enabled_by_default={}, side_effect={}, ' \ - 'priority={}, requires_output={})'.format( - self.name, self.match, self.get_new_command, - self.enabled_by_default, self.side_effect, - self.priority, self.requires_output) + return ( + 'Rule(name={}, match={}, get_new_command={}, ' \ + 'enabled_by_default={}, side_effect={}, ' \ + 'priority={}, requires_output={})'.format( + self.name, self.match, self.get_new_command, + self.enabled_by_default, self.side_effect, + self.priority, self.requires_output + ) + ) @classmethod def from_path(cls, path): From 7ed875861ded78f459d8a4d7fbffc446362a8334 Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 17:24:53 +0800 Subject: [PATCH 05/16] fix logs.py --- thefuck/logs.py | 119 ++++++++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 44 deletions(-) diff --git a/thefuck/logs.py b/thefuck/logs.py index e064de6..51d501f 100644 --- a/thefuck/logs.py +++ b/thefuck/logs.py @@ -18,22 +18,29 @@ def color(color_): def warn(title): - sys.stderr.write(u'{warn}[WARN] {title}{reset}\n'.format( - warn=color(colorama.Back.RED + colorama.Fore.WHITE - + colorama.Style.BRIGHT), - reset=color(colorama.Style.RESET_ALL), - title=title)) + sys.stderr.write( + u'{warn}[WARN] {title}{reset}\n'.format( + warn = color(colorama.Back.RED + colorama.Fore.WHITE + + colorama.Style.BRIGHT), + reset = color(colorama.Style.RESET_ALL), + title = title + ) + ) def exception(title, exc_info): sys.stderr.write( u'{warn}[WARN] {title}:{reset}\n{trace}' u'{warn}----------------------------{reset}\n\n'.format( - warn=color(colorama.Back.RED + colorama.Fore.WHITE - + colorama.Style.BRIGHT), - reset=color(colorama.Style.RESET_ALL), - title=title, - trace=''.join(format_exception(*exc_info)))) + warn = color( + colorama.Back.RED + colorama.Fore.WHITE + + colorama.Style.BRIGHT + ), + reset = color(colorama.Style.RESET_ALL), + title = title, + trace = ''.join(format_exception(*exc_info)) + ) + ) def rule_failed(rule, exc_info): @@ -41,44 +48,57 @@ def rule_failed(rule, exc_info): def failed(msg): - sys.stderr.write(u'{red}{msg}{reset}\n'.format( - msg=msg, - red=color(colorama.Fore.RED), - reset=color(colorama.Style.RESET_ALL))) + sys.stderr.write( + u'{red}{msg}{reset}\n'.format( + msg = msg, + red = color(colorama.Fore.RED), + reset = color(colorama.Style.RESET_ALL) + ) + ) def show_corrected_command(corrected_command): - sys.stderr.write(u'{prefix}{bold}{script}{reset}{side_effect}\n'.format( - prefix=const.USER_COMMAND_MARK, - script=corrected_command.script, - side_effect=u' (+side effect)' if corrected_command.side_effect else u'', - bold=color(colorama.Style.BRIGHT), - reset=color(colorama.Style.RESET_ALL))) + sys.stderr.write( + u'{prefix}{bold}{script}{reset}{side_effect}\n'.format( + prefix = const.USER_COMMAND_MARK, + script = corrected_command.script, + side_effect = u' (+side effect)' if corrected_command.side_effect else u'', + bold = color(colorama.Style.BRIGHT), + reset = color(colorama.Style.RESET_ALL) + ) + ) def confirm_text(corrected_command): sys.stderr.write( - (u'{prefix}{clear}{bold}{script}{reset}{side_effect} ' - u'[{green}enter{reset}/{blue}↑{reset}/{blue}↓{reset}' - u'/{red}ctrl+c{reset}]').format( - prefix=const.USER_COMMAND_MARK, - script=corrected_command.script, - side_effect=' (+side effect)' if corrected_command.side_effect else '', - clear='\033[1K\r', - bold=color(colorama.Style.BRIGHT), - green=color(colorama.Fore.GREEN), - red=color(colorama.Fore.RED), - reset=color(colorama.Style.RESET_ALL), - blue=color(colorama.Fore.BLUE))) + ( + u'{prefix}{clear}{bold}{script}{reset}{side_effect} ' + u'[{green}enter{reset}/{blue}↑{reset}/{blue}↓{reset}' + u'/{red}ctrl+c{reset}]' + ).format( + prefix = const.USER_COMMAND_MARK, + script = corrected_command.script, + side_effect = ' (+side effect)' if corrected_command.side_effect else '', + clear = '\033[1K\r', + bold = color(colorama.Style.BRIGHT), + green = color(colorama.Fore.GREEN), + red = color(colorama.Fore.RED), + reset = color(colorama.Style.RESET_ALL), + blue = color(colorama.Fore.BLUE) + ) + ) def debug(msg): if settings.debug: - sys.stderr.write(u'{blue}{bold}DEBUG:{reset} {msg}\n'.format( - msg=msg, - reset=color(colorama.Style.RESET_ALL), - blue=color(colorama.Fore.BLUE), - bold=color(colorama.Style.BRIGHT))) + sys.stderr.write( + u'{blue}{bold}DEBUG:{reset} {msg}\n'.format( + msg = msg, + reset = color(colorama.Style.RESET_ALL), + blue = color(colorama.Fore.BLUE), + bold = color(colorama.Style.BRIGHT) + ) + ) @contextmanager @@ -91,9 +111,12 @@ def debug_time(msg): def how_to_configure_alias(configuration_details): - print(u"Seems like {bold}fuck{reset} alias isn't configured!".format( - bold=color(colorama.Style.BRIGHT), - reset=color(colorama.Style.RESET_ALL))) + print( + u"Seems like {bold}fuck{reset} alias isn't configured!".format( + bold=color(colorama.Style.BRIGHT), + reset=color(colorama.Style.RESET_ALL) + ) + ) if configuration_details: print( @@ -102,14 +125,18 @@ def how_to_configure_alias(configuration_details): u"changes with {bold}{reload}{reset} or restart your shell.".format( bold=color(colorama.Style.BRIGHT), reset=color(colorama.Style.RESET_ALL), - **configuration_details._asdict())) + **configuration_details._asdict() + ) + ) if configuration_details.can_configure_automatically: print( u"Or run {bold}fuck{reset} a second time to configure" u" it automatically.".format( bold=color(colorama.Style.BRIGHT), - reset=color(colorama.Style.RESET_ALL))) + reset=color(colorama.Style.RESET_ALL) + ) + ) print(u'More details - https://github.com/nvbn/thefuck#manual-installation') @@ -121,7 +148,9 @@ def already_configured(configuration_details): u" or restart your shell.".format( bold=color(colorama.Style.BRIGHT), reset=color(colorama.Style.RESET_ALL), - reload=configuration_details.reload)) + reload=configuration_details.reload + ) + ) def configured_successfully(configuration_details): @@ -131,7 +160,9 @@ def configured_successfully(configuration_details): u" or restart your shell.".format( bold=color(colorama.Style.BRIGHT), reset=color(colorama.Style.RESET_ALL), - reload=configuration_details.reload)) + reload=configuration_details.reload + ) + ) def version(thefuck_version, python_version, shell_info): From cdf44a5deaf772108d941db49ae0d2998e45235c Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 17:27:34 +0800 Subject: [PATCH 06/16] fix corrector.py --- thefuck/corrector.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/thefuck/corrector.py b/thefuck/corrector.py index fdd4698..7f8b1eb 100644 --- a/thefuck/corrector.py +++ b/thefuck/corrector.py @@ -43,10 +43,16 @@ def get_rules(): :rtype: [Rule] """ - paths = [rule_path for path in get_rules_import_paths() - for rule_path in sorted(path.glob('*.py'))] - return sorted(get_loaded_rules(paths), - key=lambda rule: rule.priority) + paths = [ + rule_path for path in get_rules_import_paths() + for rule_path in sorted(path.glob('*.py')) + ] + return ( + sorted( + get_loaded_rules(paths), + key=lambda rule: rule.priority + ) + ) def organize_commands(corrected_commands): @@ -88,5 +94,6 @@ def get_corrected_commands(command): corrected_commands = ( corrected for rule in get_rules() if rule.is_match(command) - for corrected in rule.get_corrected_commands(command)) + for corrected in rule.get_corrected_commands(command) + ) return organize_commands(corrected_commands) From c3573768747148b0d27319f5db79f7f1613d2b18 Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 17:30:40 +0800 Subject: [PATCH 07/16] fix const.py --- thefuck/const.py | 82 +++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/thefuck/const.py b/thefuck/const.py index 8d33926..84547ce 100644 --- a/thefuck/const.py +++ b/thefuck/const.py @@ -15,9 +15,11 @@ KEY_CTRL_C = _GenConst('Ctrl+C') KEY_CTRL_N = _GenConst('Ctrl+N') KEY_CTRL_P = _GenConst('Ctrl+P') -KEY_MAPPING = {'\x0e': KEY_CTRL_N, - '\x03': KEY_CTRL_C, - '\x10': KEY_CTRL_P} +KEY_MAPPING = { + '\x0e': KEY_CTRL_N, + '\x03': KEY_CTRL_C, + '\x10': KEY_CTRL_P +} ACTION_SELECT = _GenConst('select') ACTION_ABORT = _GenConst('abort') @@ -28,39 +30,49 @@ ALL_ENABLED = _GenConst('All rules enabled') DEFAULT_RULES = [ALL_ENABLED] DEFAULT_PRIORITY = 1000 -DEFAULT_SETTINGS = {'rules': DEFAULT_RULES, - 'exclude_rules': [], - 'wait_command': 3, - 'require_confirmation': True, - 'no_colors': False, - 'debug': False, - 'priority': {}, - 'history_limit': None, - 'alter_history': True, - 'wait_slow_command': 15, - 'slow_commands': ['lein', 'react-native', 'gradle', - './gradlew', 'vagrant'], - 'repeat': False, - 'instant_mode': False, - 'num_close_matches': 3, - 'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}, - 'excluded_search_path_prefixes': []} +DEFAULT_SETTINGS = { + 'rules': DEFAULT_RULES, + 'exclude_rules': [], + 'wait_command': 3, + 'require_confirmation': True, + 'no_colors': False, + 'debug': False, + 'priority': {}, + 'history_limit': None, + 'alter_history': True, + 'wait_slow_command': 15, + 'slow_commands': [ + 'lein', 'react-native', 'gradle', + './gradlew', 'vagrant' + ], + 'repeat': False, + 'instant_mode': False, + 'num_close_matches': 3, + 'env': { + 'LC_ALL': 'C', + 'LANG': 'C', + 'GIT_TRACE': '1' + }, + 'excluded_search_path_prefixes': [] +} -ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', - 'THEFUCK_EXCLUDE_RULES': 'exclude_rules', - 'THEFUCK_WAIT_COMMAND': 'wait_command', - 'THEFUCK_REQUIRE_CONFIRMATION': 'require_confirmation', - 'THEFUCK_NO_COLORS': 'no_colors', - 'THEFUCK_DEBUG': 'debug', - 'THEFUCK_PRIORITY': 'priority', - 'THEFUCK_HISTORY_LIMIT': 'history_limit', - 'THEFUCK_ALTER_HISTORY': 'alter_history', - 'THEFUCK_WAIT_SLOW_COMMAND': 'wait_slow_command', - 'THEFUCK_SLOW_COMMANDS': 'slow_commands', - 'THEFUCK_REPEAT': 'repeat', - 'THEFUCK_INSTANT_MODE': 'instant_mode', - 'THEFUCK_NUM_CLOSE_MATCHES': 'num_close_matches', - 'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': 'excluded_search_path_prefixes'} +ENV_TO_ATTR = { + 'THEFUCK_RULES': 'rules', + 'THEFUCK_EXCLUDE_RULES': 'exclude_rules', + 'THEFUCK_WAIT_COMMAND': 'wait_command', + 'THEFUCK_REQUIRE_CONFIRMATION': 'require_confirmation', + 'THEFUCK_NO_COLORS': 'no_colors', + 'THEFUCK_DEBUG': 'debug', + 'THEFUCK_PRIORITY': 'priority', + 'THEFUCK_HISTORY_LIMIT': 'history_limit', + 'THEFUCK_ALTER_HISTORY': 'alter_history', + 'THEFUCK_WAIT_SLOW_COMMAND': 'wait_slow_command', + 'THEFUCK_SLOW_COMMANDS': 'slow_commands', + 'THEFUCK_REPEAT': 'repeat', + 'THEFUCK_INSTANT_MODE': 'instant_mode', + 'THEFUCK_NUM_CLOSE_MATCHES': 'num_close_matches', + 'THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES': 'excluded_search_path_prefixes' +} SETTINGS_HEADER = u"""# The Fuck settings file # From 93d5c94180542a8eae4c82ff93d2dcab15625323 Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 17:35:54 +0800 Subject: [PATCH 08/16] fix conf.py --- thefuck/conf.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/thefuck/conf.py b/thefuck/conf.py index 611ec84..5ceaf38 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -59,8 +59,11 @@ class Settings(dict): # For backward compatibility use legacy '~/.thefuck' if it exists: if legacy_user_dir.is_dir(): - warn(u'Config path {} is deprecated. Please move to {}'.format( - legacy_user_dir, user_dir)) + warn( + u'Config path {} is deprecated. Please move to {}'.format( + legacy_user_dir, user_dir + ) + ) return legacy_user_dir else: return user_dir @@ -78,9 +81,11 @@ class Settings(dict): """Loads settings from file.""" settings = load_source( 'settings', text_type(self.user_dir.joinpath('settings.py'))) - return {key: getattr(settings, key) - for key in const.DEFAULT_SETTINGS.keys() - if hasattr(settings, key)} + return { + key: getattr(settings, key) + for key in const.DEFAULT_SETTINGS.keys() + if hasattr(settings, key) + } def _rules_from_env(self, val): """Transforms rules list from env-string to python.""" @@ -118,9 +123,11 @@ class Settings(dict): def _settings_from_env(self): """Loads settings from env.""" - return {attr: self._val_from_env(env, attr) - for env, attr in const.ENV_TO_ATTR.items() - if env in os.environ} + return { + attr: self._val_from_env(env, attr) + for env, attr in const.ENV_TO_ATTR.items() + if env in os.environ + } def _settings_from_args(self, args): """Loads settings from args.""" From 7e04500b9608485d478ea4833c055a8871b4162b Mon Sep 17 00:00:00 2001 From: DashBing Date: Sun, 20 Aug 2023 18:19:27 +0800 Subject: [PATCH 09/16] fix argument_parser.py --- thefuck/argument_parser.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/thefuck/argument_parser.py b/thefuck/argument_parser.py index 69c247f..058a54b 100644 --- a/thefuck/argument_parser.py +++ b/thefuck/argument_parser.py @@ -19,37 +19,45 @@ class Parser(object): self._parser.add_argument( '-v', '--version', action='store_true', - help="show program's version number and exit") + help="show program's version number and exit" + ) self._parser.add_argument( '-a', '--alias', nargs='?', const=get_alias(), - help='[custom-alias-name] prints alias for current shell') + help='[custom-alias-name] prints alias for current shell' + ) self._parser.add_argument( '-l', '--shell-logger', action='store', - help='log shell output to the file') + help='log shell output to the file' + ) self._parser.add_argument( '--enable-experimental-instant-mode', action='store_true', - help='enable experimental instant mode, use on your own risk') + help='enable experimental instant mode, use on your own risk' + ) self._parser.add_argument( '-h', '--help', action='store_true', - help='show this help message and exit') + help='show this help message and exit' + ) self._add_conflicting_arguments() self._parser.add_argument( '-d', '--debug', action='store_true', - help='enable debug output') + help='enable debug output' + ) self._parser.add_argument( '--force-command', action='store', - help=SUPPRESS) + help=SUPPRESS + ) self._parser.add_argument( 'command', nargs='*', - help='command that should be fixed') + help='command that should be fixed' + ) def _add_conflicting_arguments(self): """It's too dangerous to use `-y` and `-r` together.""" @@ -57,11 +65,13 @@ class Parser(object): group.add_argument( '-y', '--yes', '--yeah', '--hard', action='store_true', - help='execute fixed command without confirmation') + help='execute fixed command without confirmation' + ) group.add_argument( '-r', '--repeat', action='store_true', - help='repeat on failure') + help='repeat on failure' + ) def _prepare_arguments(self, argv): """Prepares arguments by: From f34bc3d49abd9412ec8291dff3a07bf84c70be33 Mon Sep 17 00:00:00 2001 From: DashBing Date: Mon, 21 Aug 2023 10:26:32 +0800 Subject: [PATCH 10/16] fix many files --- thefuck/shells/__init__.py | 16 +++++++------ thefuck/shells/bash.py | 44 +++++++++++++++++++++++------------ thefuck/specific/archlinux.py | 3 ++- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/thefuck/shells/__init__.py b/thefuck/shells/__init__.py index 3da6497..c3ff52e 100644 --- a/thefuck/shells/__init__.py +++ b/thefuck/shells/__init__.py @@ -11,13 +11,15 @@ from .tcsh import Tcsh from .zsh import Zsh from .powershell import Powershell -shells = {'bash': Bash, - 'fish': Fish, - 'zsh': Zsh, - 'csh': Tcsh, - 'tcsh': Tcsh, - 'powershell': Powershell, - 'pwsh': Powershell} +shells = { + 'bash': Bash, + 'fish': Fish, + 'zsh': Zsh, + 'csh': Tcsh, + 'tcsh': Tcsh, + 'powershell': Powershell, + 'pwsh': Powershell +} def _get_shell_from_env(): diff --git a/thefuck/shells/bash.py b/thefuck/shells/bash.py index fa7a207..fcb7fe4 100644 --- a/thefuck/shells/bash.py +++ b/thefuck/shells/bash.py @@ -13,7 +13,7 @@ class Bash(Generic): def app_alias(self, alias_name): # It is VERY important to have the variables declared WITHIN the function - return ''' + return (''' function {name} () {{ TF_PYTHONIOENCODING=$PYTHONIOENCODING; export TF_SHELL=bash; @@ -29,19 +29,26 @@ class Bash(Generic): {alter_history} }} '''.format( - name=alias_name, - argument_placeholder=ARGUMENT_PLACEHOLDER, - alter_history=('history -s $TF_CMD;' - if settings.alter_history else '')) + name=alias_name, + argument_placeholder=ARGUMENT_PLACEHOLDER, + alter_history=( + 'history -s $TF_CMD;' + if settings.alter_history else '' + ) + ) + ) def instant_mode_alias(self, alias_name): if os.environ.get('THEFUCK_INSTANT_MODE', '').lower() == 'true': mark = USER_COMMAND_MARK + '\b' * len(USER_COMMAND_MARK) - return ''' + return(''' export PS1="{user_command_mark}$PS1"; {app_alias} - '''.format(user_command_mark=mark, - app_alias=self.app_alias(alias_name)) + '''.format( + user_command_mark=mark, + app_alias=self.app_alias(alias_name) + ) + ) else: log_path = os.path.join( gettempdir(), 'thefuck-script-log-{}'.format(uuid4().hex)) @@ -62,12 +69,16 @@ class Bash(Generic): @memoize def get_aliases(self): raw_aliases = os.environ.get('TF_SHELL_ALIASES', '').split('\n') - return dict(self._parse_alias(alias) - for alias in raw_aliases if alias and '=' in alias) + return dict( + self._parse_alias(alias) + for alias in raw_aliases if alias and '=' in alias + ) def _get_history_file_name(self): - return os.environ.get("HISTFILE", - os.path.expanduser('~/.bash_history')) + return os.environ.get( + "HISTFILE", + os.path.expanduser('~/.bash_history') + ) def _get_history_line(self, command_script): return u'{}\n'.format(command_script) @@ -83,10 +94,13 @@ class Bash(Generic): return self._create_shell_configuration( content=u'eval "$(thefuck --alias)"', path=config, - reload=u'source {}'.format(config)) + reload=u'source {}'.format(config) + ) def _get_version(self): """Returns the version of the current shell""" - proc = Popen(['bash', '-c', 'echo $BASH_VERSION'], - stdout=PIPE, stderr=DEVNULL) + proc = Popen( + ['bash', '-c', 'echo $BASH_VERSION'], + stdout=PIPE, stderr=DEVNULL + ) return proc.stdout.read().decode('utf-8').strip() diff --git a/thefuck/specific/archlinux.py b/thefuck/specific/archlinux.py index a64bfda..8dede60 100644 --- a/thefuck/specific/archlinux.py +++ b/thefuck/specific/archlinux.py @@ -20,7 +20,8 @@ def get_pkgfile(command): packages = subprocess.check_output( ['pkgfile', '-b', '-v', command], - universal_newlines=True, stderr=utils.DEVNULL + universal_newlines=True, + stderr=utils.DEVNULL ).splitlines() return [package.split()[0] for package in packages] From 15526bc8170073bbe2d8c62e1b0b9d6403139f5e Mon Sep 17 00:00:00 2001 From: DashBing Date: Mon, 21 Aug 2023 10:44:08 +0800 Subject: [PATCH 11/16] fix half of rules/* --- thefuck/rules/apt_invalid_operation.py | 8 +++--- thefuck/rules/brew_install.py | 8 +++--- thefuck/rules/brew_link.py | 6 +++-- thefuck/rules/brew_reinstall.py | 12 ++++++--- thefuck/rules/brew_uninstall.py | 6 +++-- thefuck/rules/brew_unknown_command.py | 34 +++++++++++++++++--------- thefuck/rules/brew_update_formula.py | 8 +++--- thefuck/rules/cargo_no_command.py | 6 +++-- thefuck/rules/cd_correction.py | 13 ++++++---- thefuck/rules/cd_mkdir.py | 13 ++++++---- thefuck/rules/chmod_x.py | 6 +++-- thefuck/rules/choco_install.py | 6 +++-- thefuck/rules/composer_not_command.py | 12 ++++++--- thefuck/rules/cpp11.py | 8 +++--- thefuck/rules/dirty_untar.py | 16 +++++++----- thefuck/rules/dnf_no_such_command.py | 8 +++--- thefuck/rules/fab_command_not_found.py | 12 ++++++--- thefuck/rules/fix_alt_space.py | 6 +++-- thefuck/rules/fix_file.py | 26 +++++++++++++------- thefuck/rules/gem_unknown_command.py | 12 ++++++--- thefuck/rules/git_add.py | 3 ++- thefuck/rules/git_add_force.py | 6 +++-- thefuck/rules/git_bisect_usage.py | 6 +++-- thefuck/rules/git_branch_delete.py | 6 +++-- thefuck/rules/git_branch_exists.py | 18 ++++++++------ thefuck/rules/git_checkout.py | 19 +++++++++----- thefuck/rules/git_clone_git_clone.py | 6 +++-- thefuck/rules/git_diff_no_index.py | 14 +++++++---- thefuck/rules/git_diff_staged.py | 6 +++-- thefuck/rules/git_fix_stash.py | 9 ++++--- thefuck/rules/git_merge.py | 8 +++--- thefuck/rules/git_merge_unrelated.py | 6 +++-- thefuck/rules/git_not_command.py | 16 ++++++++---- thefuck/rules/git_pull_clone.py | 6 +++-- 34 files changed, 232 insertions(+), 123 deletions(-) diff --git a/thefuck/rules/apt_invalid_operation.py b/thefuck/rules/apt_invalid_operation.py index 8641939..5c478a6 100644 --- a/thefuck/rules/apt_invalid_operation.py +++ b/thefuck/rules/apt_invalid_operation.py @@ -40,9 +40,11 @@ def _parse_apt_get_and_cache_operations(help_text_lines): def _get_operations(app): - proc = subprocess.Popen([app, '--help'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + proc = subprocess.Popen( + [app, '--help'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) lines = proc.stdout.readlines() if app == 'apt': diff --git a/thefuck/rules/brew_install.py b/thefuck/rules/brew_install.py index d285a2d..0f0a65b 100644 --- a/thefuck/rules/brew_install.py +++ b/thefuck/rules/brew_install.py @@ -12,9 +12,11 @@ def _get_suggestions(str): @for_app('brew', at_least=2) def match(command): - is_proper_command = ('install' in command.script and - 'No available formula' in command.output and - 'Did you mean' in command.output) + is_proper_command = ( + 'install' in command.script and + 'No available formula' in command.output and + 'Did you mean' in command.output + ) return is_proper_command diff --git a/thefuck/rules/brew_link.py b/thefuck/rules/brew_link.py index b8a158f..d7f0ee2 100644 --- a/thefuck/rules/brew_link.py +++ b/thefuck/rules/brew_link.py @@ -3,8 +3,10 @@ from thefuck.utils import for_app @for_app('brew', at_least=2) def match(command): - return (command.script_parts[1] in ['ln', 'link'] - and "brew link --overwrite --dry-run" in command.output) + return ( + command.script_parts[1] in ['ln', 'link'] + and "brew link --overwrite --dry-run" in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/brew_reinstall.py b/thefuck/rules/brew_reinstall.py index bc14e69..c0c34c7 100644 --- a/thefuck/rules/brew_reinstall.py +++ b/thefuck/rules/brew_reinstall.py @@ -2,10 +2,14 @@ import re from thefuck.utils import for_app -warning_regex = re.compile(r'Warning: (?:.(?!is ))+ is already installed and ' - r'up-to-date') -message_regex = re.compile(r'To reinstall (?:(?!, ).)+, run `brew reinstall ' - r'[^`]+`') +warning_regex = re.compile( + r'Warning: (?:.(?!is ))+ is already installed and ' + r'up-to-date' +) +message_regex = re.compile( + r'To reinstall (?:(?!, ).)+, run `brew reinstall ' + r'[^`]+`' +) @for_app('brew', at_least=2) diff --git a/thefuck/rules/brew_uninstall.py b/thefuck/rules/brew_uninstall.py index 222a25f..57d2b0d 100644 --- a/thefuck/rules/brew_uninstall.py +++ b/thefuck/rules/brew_uninstall.py @@ -3,8 +3,10 @@ from thefuck.utils import for_app @for_app('brew', at_least=2) def match(command): - return (command.script_parts[1] in ['uninstall', 'rm', 'remove'] - and "brew uninstall --force" in command.output) + return ( + command.script_parts[1] in ['uninstall', 'rm', 'remove'] + and "brew uninstall --force" in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/brew_unknown_command.py b/thefuck/rules/brew_unknown_command.py index 244f48a..5e7e557 100644 --- a/thefuck/rules/brew_unknown_command.py +++ b/thefuck/rules/brew_unknown_command.py @@ -14,8 +14,10 @@ def _get_brew_commands(brew_path_prefix): """To get brew default commands on local environment""" brew_cmd_path = brew_path_prefix + BREW_CMD_PATH - return [name[:-3] for name in os.listdir(brew_cmd_path) - if name.endswith(('.rb', '.sh'))] + return [ + name[:-3] for name in os.listdir(brew_cmd_path) + if name.endswith(('.rb', '.sh')) + ] def _get_brew_tap_specific_commands(brew_path_prefix): @@ -34,9 +36,11 @@ def _get_brew_tap_specific_commands(brew_path_prefix): tap_cmd_path = brew_taps_path + TAP_CMD_PATH % (user, tap) if os.path.isdir(tap_cmd_path): - commands += (name.replace('brew-', '').replace('.rb', '') - for name in os.listdir(tap_cmd_path) - if _is_brew_tap_cmd_naming(name)) + commands += ( + name.replace('brew-', '').replace('.rb', '') + for name in os.listdir(tap_cmd_path) + if _is_brew_tap_cmd_naming(name) + ) return commands @@ -46,23 +50,29 @@ def _is_brew_tap_cmd_naming(name): def _get_directory_names_only(path): - return [d for d in os.listdir(path) - if os.path.isdir(os.path.join(path, d))] + return [ + d for d in os.listdir(path) + if os.path.isdir(os.path.join(path, d)) + ] def _brew_commands(): brew_path_prefix = get_brew_path_prefix() if brew_path_prefix: try: - return (_get_brew_commands(brew_path_prefix) - + _get_brew_tap_specific_commands(brew_path_prefix)) + return ( + _get_brew_commands(brew_path_prefix) + + _get_brew_tap_specific_commands(brew_path_prefix) + ) except OSError: pass # Failback commands for testing (Based on Homebrew 0.9.5) - return ['info', 'home', 'options', 'install', 'uninstall', - 'search', 'list', 'update', 'upgrade', 'pin', 'unpin', - 'doctor', 'create', 'edit', 'cask'] + return [ + 'info', 'home', 'options', 'install', 'uninstall', + 'search', 'list', 'update', 'upgrade', 'pin', 'unpin', + 'doctor', 'create', 'edit', 'cask' + ] def match(command): diff --git a/thefuck/rules/brew_update_formula.py b/thefuck/rules/brew_update_formula.py index 4f2264a..4dcfc82 100644 --- a/thefuck/rules/brew_update_formula.py +++ b/thefuck/rules/brew_update_formula.py @@ -3,9 +3,11 @@ from thefuck.utils import for_app @for_app('brew', at_least=2) def match(command): - return ('update' in command.script - and "Error: This command updates brew itself" in command.output - and "Use `brew upgrade" in command.output) + return ( + 'update' in command.script + and "Error: This command updates brew itself" in command.output + and "Use `brew upgrade" in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/cargo_no_command.py b/thefuck/rules/cargo_no_command.py index 687f40a..f8eac9a 100644 --- a/thefuck/rules/cargo_no_command.py +++ b/thefuck/rules/cargo_no_command.py @@ -4,8 +4,10 @@ from thefuck.utils import replace_argument, for_app @for_app('cargo', at_least=1) def match(command): - return ('no such subcommand' in command.output.lower() - and 'Did you mean' in command.output) + return ( + 'no such subcommand' in command.output.lower() + and 'Did you mean' in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/cd_correction.py b/thefuck/rules/cd_correction.py index dc45636..2d3e12f 100644 --- a/thefuck/rules/cd_correction.py +++ b/thefuck/rules/cd_correction.py @@ -21,11 +21,14 @@ def _get_sub_dirs(parent): def match(command): """Match function copied from cd_mkdir.py""" return ( - command.script.startswith('cd ') and any(( - 'no such file or directory' in command.output.lower(), - 'cd: can\'t cd to' in command.output.lower(), - 'does not exist' in command.output.lower() - ))) + command.script.startswith('cd ') and any( + ( + 'no such file or directory' in command.output.lower(), + 'cd: can\'t cd to' in command.output.lower(), + 'does not exist' in command.output.lower() + ) + ) + ) @sudo_support diff --git a/thefuck/rules/cd_mkdir.py b/thefuck/rules/cd_mkdir.py index 363b92d..53aa227 100644 --- a/thefuck/rules/cd_mkdir.py +++ b/thefuck/rules/cd_mkdir.py @@ -8,11 +8,14 @@ from thefuck.shells import shell @for_app('cd') def match(command): return ( - command.script.startswith('cd ') and any(( - 'no such file or directory' in command.output.lower(), - 'cd: can\'t cd to' in command.output.lower(), - 'does not exist' in command.output.lower() - ))) + command.script.startswith('cd ') and any( + ( + 'no such file or directory' in command.output.lower(), + 'cd: can\'t cd to' in command.output.lower(), + 'does not exist' in command.output.lower() + ) + ) + ) @sudo_support diff --git a/thefuck/rules/chmod_x.py b/thefuck/rules/chmod_x.py index 09e685e..7cc317a 100644 --- a/thefuck/rules/chmod_x.py +++ b/thefuck/rules/chmod_x.py @@ -3,10 +3,12 @@ from thefuck.shells import shell def match(command): - return (command.script.startswith('./') + return ( + command.script.startswith('./') and 'permission denied' in command.output.lower() and os.path.exists(command.script_parts[0]) - and not os.access(command.script_parts[0], os.X_OK)) + and not os.access(command.script_parts[0], os.X_OK) + ) def get_new_command(command): diff --git a/thefuck/rules/choco_install.py b/thefuck/rules/choco_install.py index 8c07302..0671ca7 100644 --- a/thefuck/rules/choco_install.py +++ b/thefuck/rules/choco_install.py @@ -3,8 +3,10 @@ from thefuck.utils import for_app, which @for_app("choco", "cinst") def match(command): - return ((command.script.startswith('choco install') or 'cinst' in command.script_parts) - and 'Installing the following packages' in command.output) + return ( + (command.script.startswith('choco install') or 'cinst' in command.script_parts) + and 'Installing the following packages' in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/composer_not_command.py b/thefuck/rules/composer_not_command.py index b678800..ddae57a 100644 --- a/thefuck/rules/composer_not_command.py +++ b/thefuck/rules/composer_not_command.py @@ -4,9 +4,15 @@ from thefuck.utils import replace_argument, for_app @for_app('composer') def match(command): - return (('did you mean this?' in command.output.lower() - or 'did you mean one of these?' in command.output.lower())) or ( - "install" in command.script_parts and "composer require" in command.output.lower() + return ( + ( + ( + 'did you mean this?' in command.output.lower() + or 'did you mean one of these?' in command.output.lower() + ) + ) or ( + "install" in command.script_parts and "composer require" in command.output.lower() + ) ) diff --git a/thefuck/rules/cpp11.py b/thefuck/rules/cpp11.py index 99bbf34..2d46591 100644 --- a/thefuck/rules/cpp11.py +++ b/thefuck/rules/cpp11.py @@ -3,9 +3,11 @@ from thefuck.utils import for_app @for_app('g++', 'clang++') def match(command): - return ('This file requires compiler and library support for the ' - 'ISO C++ 2011 standard.' in command.output or - '-Wc++11-extensions' in command.output) + return ( + 'This file requires compiler and library support for the ' + 'ISO C++ 2011 standard.' in command.output or + '-Wc++11-extensions' in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/dirty_untar.py b/thefuck/rules/dirty_untar.py index 638aa87..9876f9e 100644 --- a/thefuck/rules/dirty_untar.py +++ b/thefuck/rules/dirty_untar.py @@ -4,9 +4,11 @@ from thefuck.utils import for_app from thefuck.shells import shell -tar_extensions = ('.tar', '.tar.Z', '.tar.bz2', '.tar.gz', '.tar.lz', - '.tar.lzma', '.tar.xz', '.taz', '.tb2', '.tbz', '.tbz2', - '.tgz', '.tlz', '.txz', '.tz') +tar_extensions = ( + '.tar', '.tar.Z', '.tar.bz2', '.tar.gz', '.tar.lz', + '.tar.lzma', '.tar.xz', '.taz', '.tb2', '.tbz', '.tbz2', + '.tgz', '.tlz', '.txz', '.tz' +) def _is_tar_extract(cmd): @@ -27,9 +29,11 @@ def _tar_file(cmd): @for_app('tar') def match(command): - return ('-C' not in command.script - and _is_tar_extract(command.script) - and _tar_file(command.script_parts) is not None) + return ( + '-C' not in command.script + and _is_tar_extract(command.script) + and _tar_file(command.script_parts) is not None + ) def get_new_command(command): diff --git a/thefuck/rules/dnf_no_such_command.py b/thefuck/rules/dnf_no_such_command.py index 579f578..aa95fc3 100644 --- a/thefuck/rules/dnf_no_such_command.py +++ b/thefuck/rules/dnf_no_such_command.py @@ -20,9 +20,11 @@ def _parse_operations(help_text_lines): def _get_operations(): - proc = subprocess.Popen(["dnf", '--help'], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + proc = subprocess.Popen( + ["dnf", '--help'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) lines = proc.stdout.read().decode("utf-8") return _parse_operations(lines) diff --git a/thefuck/rules/fab_command_not_found.py b/thefuck/rules/fab_command_not_found.py index 05d6df0..0506d5e 100644 --- a/thefuck/rules/fab_command_not_found.py +++ b/thefuck/rules/fab_command_not_found.py @@ -25,14 +25,18 @@ def _get_between(content, start, end=None): def get_new_command(command): not_found_commands = _get_between( command.output, 'Warning: Command(s) not found:', - 'Available commands:') + 'Available commands:' + ) possible_commands = _get_between( - command.output, 'Available commands:') + command.output, 'Available commands:' + ) script = command.script for not_found in not_found_commands: fix = get_closest(not_found, possible_commands) - script = script.replace(' {}'.format(not_found), - ' {}'.format(fix)) + script = script.replace( + ' {}'.format(not_found), + ' {}'.format(fix) + ) return script diff --git a/thefuck/rules/fix_alt_space.py b/thefuck/rules/fix_alt_space.py index bf2d320..9328fd3 100644 --- a/thefuck/rules/fix_alt_space.py +++ b/thefuck/rules/fix_alt_space.py @@ -6,8 +6,10 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return ('command not found' in command.output.lower() - and u' ' in command.script) + return ( + 'command not found' in command.output.lower() + and u' ' in command.script + ) @sudo_support diff --git a/thefuck/rules/fix_file.py b/thefuck/rules/fix_file.py index d091c2a..7d9501c 100644 --- a/thefuck/rules/fix_file.py +++ b/thefuck/rules/fix_file.py @@ -60,21 +60,29 @@ def match(command): return _search(command.output) -@default_settings({'fixlinecmd': u'{editor} {file} +{line}', - 'fixcolcmd': None}) +@default_settings( + { + 'fixlinecmd': u'{editor} {file} +{line}', + 'fixcolcmd': None + } +) def get_new_command(command): m = _search(command.output) # Note: there does not seem to be a standard for columns, so they are just # ignored by default if settings.fixcolcmd and 'col' in m.groupdict(): - editor_call = settings.fixcolcmd.format(editor=os.environ['EDITOR'], - file=m.group('file'), - line=m.group('line'), - col=m.group('col')) + editor_call = settings.fixcolcmd.format( + editor=os.environ['EDITOR'], + file=m.group('file'), + line=m.group('line'), + col=m.group('col') + ) else: - editor_call = settings.fixlinecmd.format(editor=os.environ['EDITOR'], - file=m.group('file'), - line=m.group('line')) + editor_call = settings.fixlinecmd.format( + editor=os.environ['EDITOR'], + file=m.group('file'), + line=m.group('line') + ) return shell.and_(editor_call, command.script) diff --git a/thefuck/rules/gem_unknown_command.py b/thefuck/rules/gem_unknown_command.py index 96da2f2..a770f0b 100644 --- a/thefuck/rules/gem_unknown_command.py +++ b/thefuck/rules/gem_unknown_command.py @@ -5,9 +5,11 @@ from thefuck.utils import for_app, eager, replace_command, cache, which @for_app('gem') def match(command): - return ('ERROR: While executing gem ... (Gem::CommandLineError)' + return ( + 'ERROR: While executing gem ... (Gem::CommandLineError)' in command.output - and 'Unknown command' in command.output) + and 'Unknown command' in command.output + ) def _get_unknown_command(command): @@ -16,8 +18,10 @@ def _get_unknown_command(command): @eager def _get_all_commands(): - proc = subprocess.Popen(['gem', 'help', 'commands'], - stdout=subprocess.PIPE) + proc = subprocess.Popen( + ['gem', 'help', 'commands'], + stdout=subprocess.PIPE + ) for line in proc.stdout.readlines(): line = line.decode() diff --git a/thefuck/rules/git_add.py b/thefuck/rules/git_add.py index 0230d47..97ea2de 100644 --- a/thefuck/rules/git_add.py +++ b/thefuck/rules/git_add.py @@ -9,7 +9,8 @@ from thefuck.utils import memoize def _get_missing_file(command): pathspec = re.findall( r"error: pathspec '([^']*)' " - r'did not match any file\(s\) known to git.', command.output)[0] + r'did not match any file\(s\) known to git.', command.output + )[0] if Path(pathspec).exists(): return pathspec diff --git a/thefuck/rules/git_add_force.py b/thefuck/rules/git_add_force.py index 91aba57..d5c224d 100644 --- a/thefuck/rules/git_add_force.py +++ b/thefuck/rules/git_add_force.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('add' in command.script_parts - and 'Use -f if you really want to add them.' in command.output) + return ( + 'add' in command.script_parts + and 'Use -f if you really want to add them.' in command.output + ) @git_support diff --git a/thefuck/rules/git_bisect_usage.py b/thefuck/rules/git_bisect_usage.py index 37b05f4..36728f2 100644 --- a/thefuck/rules/git_bisect_usage.py +++ b/thefuck/rules/git_bisect_usage.py @@ -5,8 +5,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('bisect' in command.script_parts and - 'usage: git bisect' in command.output) + return ( + 'bisect' in command.script_parts and + 'usage: git bisect' in command.output + ) @git_support diff --git a/thefuck/rules/git_branch_delete.py b/thefuck/rules/git_branch_delete.py index e45102c..fb4f145 100644 --- a/thefuck/rules/git_branch_delete.py +++ b/thefuck/rules/git_branch_delete.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('branch -d' in command.script - and 'If you are sure you want to delete it' in command.output) + return ( + 'branch -d' in command.script + and 'If you are sure you want to delete it' in command.output + ) @git_support diff --git a/thefuck/rules/git_branch_exists.py b/thefuck/rules/git_branch_exists.py index 4a7a822..667496a 100644 --- a/thefuck/rules/git_branch_exists.py +++ b/thefuck/rules/git_branch_exists.py @@ -6,8 +6,10 @@ from thefuck.utils import eager @git_support def match(command): - return ("fatal: A branch named '" in command.output - and "' already exists." in command.output) + return ( + "fatal: A branch named '" in command.output + and "' already exists." in command.output + ) @git_support @@ -16,10 +18,12 @@ def get_new_command(command): branch_name = re.findall( r"fatal: A branch named '(.+)' already exists.", command.output)[0] branch_name = branch_name.replace("'", r"\'") - new_command_templates = [['git branch -d {0}', 'git branch {0}'], - ['git branch -d {0}', 'git checkout -b {0}'], - ['git branch -D {0}', 'git branch {0}'], - ['git branch -D {0}', 'git checkout -b {0}'], - ['git checkout {0}']] + new_command_templates = [ + ['git branch -d {0}', 'git branch {0}'], + ['git branch -d {0}', 'git checkout -b {0}'], + ['git branch -D {0}', 'git branch {0}'], + ['git branch -D {0}', 'git checkout -b {0}'], + ['git checkout {0}'] + ] for new_command_template in new_command_templates: yield shell.and_(*new_command_template).format(branch_name) diff --git a/thefuck/rules/git_checkout.py b/thefuck/rules/git_checkout.py index e487973..f5ae369 100644 --- a/thefuck/rules/git_checkout.py +++ b/thefuck/rules/git_checkout.py @@ -8,8 +8,10 @@ from thefuck.shells import shell @git_support def match(command): - return ('did not match any file(s) known to git' in command.output - and "Did you forget to 'git add'?" not in command.output) + return ( + 'did not match any file(s) known to git' in command.output + and "Did you forget to 'git add'?" not in command.output + ) def get_branches(): @@ -32,8 +34,10 @@ def get_new_command(command): missing_file = re.findall( r"error: pathspec '([^']*)' " r"did not match any file\(s\) known to git", command.output)[0] - closest_branch = utils.get_closest(missing_file, get_branches(), - fallback_to_first=False) + closest_branch = utils.get_closest( + missing_file, get_branches(), + fallback_to_first=False + ) new_commands = [] @@ -43,7 +47,10 @@ def get_new_command(command): new_commands.append(replace_argument(command.script, 'checkout', 'checkout -b')) if not new_commands: - new_commands.append(shell.and_('git branch {}', '{}').format( - missing_file, command.script)) + new_commands.append( + shell.and_('git branch {}', '{}').format( + missing_file, command.script + ) + ) return new_commands diff --git a/thefuck/rules/git_clone_git_clone.py b/thefuck/rules/git_clone_git_clone.py index 38bab25..5913b69 100644 --- a/thefuck/rules/git_clone_git_clone.py +++ b/thefuck/rules/git_clone_git_clone.py @@ -3,8 +3,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' git clone ' in command.script - and 'fatal: Too many arguments.' in command.output) + return ( + ' git clone ' in command.script + and 'fatal: Too many arguments.' in command.output + ) @git_support diff --git a/thefuck/rules/git_diff_no_index.py b/thefuck/rules/git_diff_no_index.py index a40caef..de36ce1 100644 --- a/thefuck/rules/git_diff_no_index.py +++ b/thefuck/rules/git_diff_no_index.py @@ -4,11 +4,15 @@ from thefuck.specific.git import git_support @git_support def match(command): - files = [arg for arg in command.script_parts[2:] - if not arg.startswith('-')] - return ('diff' in command.script - and '--no-index' not in command.script - and len(files) == 2) + files = [ + arg for arg in command.script_parts[2:] + if not arg.startswith('-') + ] + return ( + 'diff' in command.script + and '--no-index' not in command.script + and len(files) == 2 + ) @git_support diff --git a/thefuck/rules/git_diff_staged.py b/thefuck/rules/git_diff_staged.py index 8afd29f..b26c79e 100644 --- a/thefuck/rules/git_diff_staged.py +++ b/thefuck/rules/git_diff_staged.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('diff' in command.script and - '--staged' not in command.script) + return ( + 'diff' in command.script and + '--staged' not in command.script + ) @git_support diff --git a/thefuck/rules/git_fix_stash.py b/thefuck/rules/git_fix_stash.py index e68aa06..53cb1d1 100644 --- a/thefuck/rules/git_fix_stash.py +++ b/thefuck/rules/git_fix_stash.py @@ -6,8 +6,10 @@ from thefuck.specific.git import git_support @git_support def match(command): if command.script_parts and len(command.script_parts) > 1: - return (command.script_parts[1] == 'stash' - and 'usage:' in command.output) + return ( + command.script_parts[1] == 'stash' + and 'usage:' in command.output + ) else: return False @@ -21,7 +23,8 @@ stash_commands = ( 'list', 'pop', 'save', - 'show') + 'show' +) @git_support diff --git a/thefuck/rules/git_merge.py b/thefuck/rules/git_merge.py index 2420b67..2f99de0 100644 --- a/thefuck/rules/git_merge.py +++ b/thefuck/rules/git_merge.py @@ -5,9 +5,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('merge' in command.script - and ' - not something we can merge' in command.output - and 'Did you mean this?' in command.output) + return ( + 'merge' in command.script + and ' - not something we can merge' in command.output + and 'Did you mean this?' in command.output + ) @git_support diff --git a/thefuck/rules/git_merge_unrelated.py b/thefuck/rules/git_merge_unrelated.py index 8e32642..43efa46 100644 --- a/thefuck/rules/git_merge_unrelated.py +++ b/thefuck/rules/git_merge_unrelated.py @@ -3,8 +3,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('merge' in command.script - and 'fatal: refusing to merge unrelated histories' in command.output) + return ( + 'merge' in command.script + and 'fatal: refusing to merge unrelated histories' in command.output + ) @git_support diff --git a/thefuck/rules/git_not_command.py b/thefuck/rules/git_not_command.py index fd2a1bd..eac3554 100644 --- a/thefuck/rules/git_not_command.py +++ b/thefuck/rules/git_not_command.py @@ -5,14 +5,20 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (" is not a git command. See 'git --help'." in command.output - and ('The most similar command' in command.output - or 'Did you mean' in command.output)) + return ( + " is not a git command. See 'git --help'." in command.output + and ( + 'The most similar command' in command.output + or 'Did you mean' in command.output + ) + ) @git_support def get_new_command(command): - broken_cmd = re.findall(r"git: '([^']*)' is not a git command", - command.output)[0] + broken_cmd = re.findall( + r"git: '([^']*)' is not a git command", + command.output + )[0] matched = get_all_matched_commands(command.output, ['The most similar command', 'Did you mean']) return replace_command(command, broken_cmd, matched) diff --git a/thefuck/rules/git_pull_clone.py b/thefuck/rules/git_pull_clone.py index c61b035..d428553 100644 --- a/thefuck/rules/git_pull_clone.py +++ b/thefuck/rules/git_pull_clone.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('fatal: Not a git repository' in command.output - and "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." in command.output) + return ( + 'fatal: Not a git repository' in command.output + and "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." in command.output + ) @git_support From b7fc483ca46438162e85e163bc57427081edde74 Mon Sep 17 00:00:00 2001 From: DashBing Date: Mon, 21 Aug 2023 10:55:29 +0800 Subject: [PATCH 12/16] fix many files in rules/ --- thefuck/rules/git_pull_uncommitted_changes.py | 10 +++++-- thefuck/rules/git_push.py | 12 +++++--- thefuck/rules/git_push_force.py | 6 ++-- thefuck/rules/git_push_pull.py | 26 +++++++++++------ thefuck/rules/git_rebase_merge_dir.py | 8 +++-- thefuck/rules/git_remote_seturl_add.py | 6 ++-- thefuck/rules/git_rm_local_modifications.py | 8 +++-- thefuck/rules/git_rm_recursive.py | 8 +++-- thefuck/rules/git_rm_staged.py | 8 +++-- thefuck/rules/git_stash_pop.py | 8 +++-- thefuck/rules/git_tag_force.py | 6 ++-- thefuck/rules/git_two_dashes.py | 6 ++-- thefuck/rules/go_run.py | 6 ++-- thefuck/rules/go_unknown_command.py | 6 ++-- thefuck/rules/gradle_wrapper.py | 8 +++-- thefuck/rules/grunt_task_not_found.py | 6 ++-- thefuck/rules/gulp_not_task.py | 18 ++++++++---- thefuck/rules/history.py | 14 ++++++--- thefuck/rules/hostscli.py | 3 +- thefuck/rules/lein_not_task.py | 12 +++++--- thefuck/rules/ln_no_hard_link.py | 6 ++-- thefuck/rules/ln_s_order.py | 6 ++-- thefuck/rules/man_no_space.py | 6 ++-- thefuck/rules/mercurial.py | 6 ++-- .../rules/missing_space_before_subcommand.py | 6 ++-- thefuck/rules/mkdir_p.py | 6 ++-- thefuck/rules/mvn_no_command.py | 6 ++-- thefuck/rules/mvn_unknown_lifecycle_phase.py | 9 ++++-- thefuck/rules/no_command.py | 29 +++++++++++++------ 29 files changed, 176 insertions(+), 89 deletions(-) diff --git a/thefuck/rules/git_pull_uncommitted_changes.py b/thefuck/rules/git_pull_uncommitted_changes.py index 152503c..c9d8954 100644 --- a/thefuck/rules/git_pull_uncommitted_changes.py +++ b/thefuck/rules/git_pull_uncommitted_changes.py @@ -4,9 +4,13 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('pull' in command.script - and ('You have unstaged changes' in command.output - or 'contains uncommitted changes' in command.output)) + return ( + 'pull' in command.script + and ( + 'You have unstaged changes' in command.output + or 'contains uncommitted changes' in command.output + ) + ) @git_support diff --git a/thefuck/rules/git_push.py b/thefuck/rules/git_push.py index 018ff15..d339c3e 100644 --- a/thefuck/rules/git_push.py +++ b/thefuck/rules/git_push.py @@ -5,8 +5,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('push' in command.script_parts - and 'git push --set-upstream' in command.output) + return ( + 'push' in command.script_parts + and 'git push --set-upstream' in command.output + ) def _get_upstream_option_index(command_parts): @@ -40,5 +42,7 @@ def get_new_command(command): command_parts.pop(len(command_parts) - 1) arguments = re.findall(r'git push (.*)', command.output)[-1].replace("'", r"\'").strip() - return replace_argument(" ".join(command_parts), 'push', - 'push {}'.format(arguments)) + return replace_argument( + " ".join(command_parts), 'push', + 'push {}'.format(arguments) + ) diff --git a/thefuck/rules/git_push_force.py b/thefuck/rules/git_push_force.py index 45c56ec..f9a8b59 100644 --- a/thefuck/rules/git_push_force.py +++ b/thefuck/rules/git_push_force.py @@ -4,10 +4,12 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('push' in command.script + return ( + 'push' in command.script and '! [rejected]' in command.output and 'failed to push some refs to' in command.output - and 'Updates were rejected because the tip of your current branch is behind' in command.output) + and 'Updates were rejected because the tip of your current branch is behind' in command.output + ) @git_support diff --git a/thefuck/rules/git_push_pull.py b/thefuck/rules/git_push_pull.py index 59ab1d5..3539b60 100644 --- a/thefuck/rules/git_push_pull.py +++ b/thefuck/rules/git_push_pull.py @@ -5,16 +5,24 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('push' in command.script and - '! [rejected]' in command.output and - 'failed to push some refs to' in command.output and - ('Updates were rejected because the tip of your' - ' current branch is behind' in command.output or - 'Updates were rejected because the remote ' - 'contains work that you do' in command.output)) + return ( + 'push' in command.script and + '! [rejected]' in command.output and + 'failed to push some refs to' in command.output and ( + ( + 'Updates were rejected because the tip of your' + ' current branch is behind' in command.output + ) or ( + 'Updates were rejected because the remote ' + 'contains work that you do' in command.output + ) + ) + ) @git_support def get_new_command(command): - return shell.and_(replace_argument(command.script, 'push', 'pull'), - command.script) + return shell.and_( + replace_argument(command.script, 'push', 'pull'), + command.script + ) diff --git a/thefuck/rules/git_rebase_merge_dir.py b/thefuck/rules/git_rebase_merge_dir.py index 8251dd1..3bc3982 100644 --- a/thefuck/rules/git_rebase_merge_dir.py +++ b/thefuck/rules/git_rebase_merge_dir.py @@ -4,9 +4,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' rebase' in command.script and - 'It seems that there is already a rebase-merge directory' in command.output and - 'I wonder if you are in the middle of another rebase' in command.output) + return ( + ' rebase' in command.script and + 'It seems that there is already a rebase-merge directory' in command.output and + 'I wonder if you are in the middle of another rebase' in command.output + ) @git_support diff --git a/thefuck/rules/git_remote_seturl_add.py b/thefuck/rules/git_remote_seturl_add.py index 39fcc93..ddda988 100644 --- a/thefuck/rules/git_remote_seturl_add.py +++ b/thefuck/rules/git_remote_seturl_add.py @@ -4,8 +4,10 @@ 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.output) + return ( + 'set-url' in command.script + and 'fatal: No such remote' in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/git_rm_local_modifications.py b/thefuck/rules/git_rm_local_modifications.py index 602fb30..6c8b4f2 100644 --- a/thefuck/rules/git_rm_local_modifications.py +++ b/thefuck/rules/git_rm_local_modifications.py @@ -3,9 +3,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' rm ' in command.script and - 'error: the following file has local modifications' in command.output and - 'use --cached to keep the file, or -f to force removal' in command.output) + return ( + ' rm ' in command.script and + 'error: the following file has local modifications' in command.output and + 'use --cached to keep the file, or -f to force removal' in command.output + ) @git_support diff --git a/thefuck/rules/git_rm_recursive.py b/thefuck/rules/git_rm_recursive.py index 5870e25..0618ac2 100644 --- a/thefuck/rules/git_rm_recursive.py +++ b/thefuck/rules/git_rm_recursive.py @@ -3,9 +3,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' rm ' in command.script - and "fatal: not removing '" in command.output - and "' recursively without -r" in command.output) + return ( + ' rm ' in command.script + and "fatal: not removing '" in command.output + and "' recursively without -r" in command.output + ) @git_support diff --git a/thefuck/rules/git_rm_staged.py b/thefuck/rules/git_rm_staged.py index 1f8e585..7816625 100644 --- a/thefuck/rules/git_rm_staged.py +++ b/thefuck/rules/git_rm_staged.py @@ -3,9 +3,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return (' rm ' in command.script and - 'error: the following file has changes staged in the index' in command.output and - 'use --cached to keep the file, or -f to force removal' in command.output) + return ( + ' rm ' in command.script and + 'error: the following file has changes staged in the index' in command.output and + 'use --cached to keep the file, or -f to force removal' in command.output + ) @git_support diff --git a/thefuck/rules/git_stash_pop.py b/thefuck/rules/git_stash_pop.py index 0e143ff..a14fa4f 100644 --- a/thefuck/rules/git_stash_pop.py +++ b/thefuck/rules/git_stash_pop.py @@ -4,9 +4,11 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('stash' in command.script - and 'pop' in command.script - and 'Your local changes to the following files would be overwritten by merge' in command.output) + return ( + 'stash' in command.script + and 'pop' in command.script + and 'Your local changes to the following files would be overwritten by merge' in command.output + ) @git_support diff --git a/thefuck/rules/git_tag_force.py b/thefuck/rules/git_tag_force.py index 63e8e39..23d20b0 100644 --- a/thefuck/rules/git_tag_force.py +++ b/thefuck/rules/git_tag_force.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('tag' in command.script_parts - and 'already exists' in command.output) + return ( + 'tag' in command.script_parts + and 'already exists' in command.output + ) @git_support diff --git a/thefuck/rules/git_two_dashes.py b/thefuck/rules/git_two_dashes.py index 3569dca..3a6f120 100644 --- a/thefuck/rules/git_two_dashes.py +++ b/thefuck/rules/git_two_dashes.py @@ -4,8 +4,10 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('error: did you mean `' in command.output - and '` (with two dashes ?)' in command.output) + return ( + 'error: did you mean `' in command.output + and '` (with two dashes ?)' in command.output + ) @git_support diff --git a/thefuck/rules/go_run.py b/thefuck/rules/go_run.py index 30db699..f5b23ab 100644 --- a/thefuck/rules/go_run.py +++ b/thefuck/rules/go_run.py @@ -8,8 +8,10 @@ from thefuck.utils import for_app @for_app('go') def match(command): - return (command.script.startswith('go run ') - and not command.script.endswith('.go')) + return ( + command.script.startswith('go run ') + and not command.script.endswith('.go') + ) def get_new_command(command): diff --git a/thefuck/rules/go_unknown_command.py b/thefuck/rules/go_unknown_command.py index 20d5242..4859c00 100644 --- a/thefuck/rules/go_unknown_command.py +++ b/thefuck/rules/go_unknown_command.py @@ -24,5 +24,7 @@ def match(command): def get_new_command(command): closest_subcommand = get_closest(command.script_parts[1], get_golang_commands()) - return replace_argument(command.script, command.script_parts[1], - closest_subcommand) + return replace_argument( + command.script, command.script_parts[1], + closest_subcommand + ) diff --git a/thefuck/rules/gradle_wrapper.py b/thefuck/rules/gradle_wrapper.py index 94b750c..1894350 100644 --- a/thefuck/rules/gradle_wrapper.py +++ b/thefuck/rules/gradle_wrapper.py @@ -4,9 +4,11 @@ from thefuck.utils import for_app, which @for_app('gradle') def match(command): - return (not which(command.script_parts[0]) - and 'not found' in command.output - and os.path.isfile('gradlew')) + return ( + not which(command.script_parts[0]) + and 'not found' in command.output + and os.path.isfile('gradlew') + ) def get_new_command(command): diff --git a/thefuck/rules/grunt_task_not_found.py b/thefuck/rules/grunt_task_not_found.py index 49bf0b4..b6284dd 100644 --- a/thefuck/rules/grunt_task_not_found.py +++ b/thefuck/rules/grunt_task_not_found.py @@ -33,5 +33,7 @@ def get_new_command(command): misspelled_task = regex.findall(command.output)[0].split(':')[0] tasks = _get_all_tasks() fixed = get_closest(misspelled_task, tasks) - return command.script.replace(' {}'.format(misspelled_task), - ' {}'.format(fixed)) + return command.script.replace( + ' {}'.format(misspelled_task), + ' {}'.format(fixed) + ) diff --git a/thefuck/rules/gulp_not_task.py b/thefuck/rules/gulp_not_task.py index e0d8589..b224731 100644 --- a/thefuck/rules/gulp_not_task.py +++ b/thefuck/rules/gulp_not_task.py @@ -10,13 +10,19 @@ def match(command): @cache('gulpfile.js') def get_gulp_tasks(): - proc = subprocess.Popen(['gulp', '--tasks-simple'], - stdout=subprocess.PIPE) - return [line.decode('utf-8')[:-1] - for line in proc.stdout.readlines()] + proc = subprocess.Popen( + ['gulp', '--tasks-simple'], + stdout=subprocess.PIPE + ) + return [ + line.decode('utf-8')[:-1] + for line in proc.stdout.readlines() + ] def get_new_command(command): - wrong_task = re.findall(r"Task '(\w+)' is not in your gulpfile", - command.output)[0] + wrong_task = re.findall( + r"Task '(\w+)' is not in your gulpfile", + command.output + )[0] return replace_command(command, wrong_task, get_gulp_tasks()) diff --git a/thefuck/rules/history.py b/thefuck/rules/history.py index 0ebe548..3a66f12 100644 --- a/thefuck/rules/history.py +++ b/thefuck/rules/history.py @@ -3,13 +3,19 @@ from thefuck.utils import get_close_matches, get_closest, \ def match(command): - return len(get_close_matches(command.script, - get_valid_history_without_current(command))) + return len( + get_close_matches( + command.script, + get_valid_history_without_current(command) + ) + ) def get_new_command(command): - return get_closest(command.script, - get_valid_history_without_current(command)) + return get_closest( + command.script, + get_valid_history_without_current(command) + ) priority = 9999 diff --git a/thefuck/rules/hostscli.py b/thefuck/rules/hostscli.py index debc9ac..6187752 100644 --- a/thefuck/rules/hostscli.py +++ b/thefuck/rules/hostscli.py @@ -22,6 +22,7 @@ def get_new_command(command): return ['hostscli websites'] misspelled_command = re.findall( - r'Error: No such command ".*"', command.output)[0] + r'Error: No such command ".*"', command.output + )[0] commands = ['block', 'unblock', 'websites', 'block_all', 'unblock_all'] return replace_command(command, misspelled_command, commands) diff --git a/thefuck/rules/lein_not_task.py b/thefuck/rules/lein_not_task.py index b960b1a..5265291 100644 --- a/thefuck/rules/lein_not_task.py +++ b/thefuck/rules/lein_not_task.py @@ -6,14 +6,18 @@ from thefuck.specific.sudo import sudo_support @sudo_support @for_app('lein') def match(command): - return (command.script.startswith('lein') + return ( + command.script.startswith('lein') and "is not a task. See 'lein help'" in command.output - and 'Did you mean this?' in command.output) + and 'Did you mean this?' in command.output + ) @sudo_support def get_new_command(command): - broken_cmd = re.findall(r"'([^']*)' is not a task", - command.output)[0] + broken_cmd = re.findall( + r"'([^']*)' is not a task", + command.output + )[0] new_cmds = get_all_matched_commands(command.output, 'Did you mean this?') return replace_command(command, broken_cmd, new_cmds) diff --git a/thefuck/rules/ln_no_hard_link.py b/thefuck/rules/ln_no_hard_link.py index 68766d3..b870528 100644 --- a/thefuck/rules/ln_no_hard_link.py +++ b/thefuck/rules/ln_no_hard_link.py @@ -14,8 +14,10 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return (command.output.endswith("hard link not allowed for directory") and - command.script_parts[0] == 'ln') + return ( + command.output.endswith("hard link not allowed for directory") + and command.script_parts[0] == 'ln' + ) @sudo_support diff --git a/thefuck/rules/ln_s_order.py b/thefuck/rules/ln_s_order.py index 963a442..58c9ad2 100644 --- a/thefuck/rules/ln_s_order.py +++ b/thefuck/rules/ln_s_order.py @@ -11,10 +11,12 @@ def _get_destination(script_parts): @sudo_support def match(command): - return (command.script_parts[0] == 'ln' + return ( + command.script_parts[0] == 'ln' and {'-s', '--symbolic'}.intersection(command.script_parts) and 'File exists' in command.output - and _get_destination(command.script_parts)) + and _get_destination(command.script_parts) + ) @sudo_support diff --git a/thefuck/rules/man_no_space.py b/thefuck/rules/man_no_space.py index 86e7716..bde4226 100644 --- a/thefuck/rules/man_no_space.py +++ b/thefuck/rules/man_no_space.py @@ -1,6 +1,8 @@ def match(command): - return (command.script.startswith(u'man') - and u'command not found' in command.output.lower()) + return ( + command.script.startswith(u'man') + and u'command not found' in command.output.lower() + ) def get_new_command(command): diff --git a/thefuck/rules/mercurial.py b/thefuck/rules/mercurial.py index ae6f7aa..f11d048 100644 --- a/thefuck/rules/mercurial.py +++ b/thefuck/rules/mercurial.py @@ -14,10 +14,12 @@ def extract_possibilities(command): @for_app('hg') def match(command): - return ('hg: unknown command' in command.output + return ( + 'hg: unknown command' in command.output and '(did you mean one of ' in command.output or "hg: command '" in command.output - and "' is ambiguous:" in command.output) + and "' is ambiguous:" in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/missing_space_before_subcommand.py b/thefuck/rules/missing_space_before_subcommand.py index fd4fbd7..932fa5d 100644 --- a/thefuck/rules/missing_space_before_subcommand.py +++ b/thefuck/rules/missing_space_before_subcommand.py @@ -9,8 +9,10 @@ def _get_executable(script_part): def match(command): - return (not command.script_parts[0] in get_all_executables() - and _get_executable(command.script_parts[0])) + return ( + not command.script_parts[0] in get_all_executables() + and _get_executable(command.script_parts[0]) + ) def get_new_command(command): diff --git a/thefuck/rules/mkdir_p.py b/thefuck/rules/mkdir_p.py index 3f781e1..66a81b0 100644 --- a/thefuck/rules/mkdir_p.py +++ b/thefuck/rules/mkdir_p.py @@ -4,8 +4,10 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return ('mkdir' in command.script - and 'No such file or directory' in command.output) + return ( + 'mkdir' in command.script + and 'No such file or directory' in command.output + ) @sudo_support diff --git a/thefuck/rules/mvn_no_command.py b/thefuck/rules/mvn_no_command.py index 36c2a0a..425ffe0 100644 --- a/thefuck/rules/mvn_no_command.py +++ b/thefuck/rules/mvn_no_command.py @@ -7,5 +7,7 @@ def match(command): def get_new_command(command): - return [command.script + ' clean package', - command.script + ' clean install'] + return [ + command.script + ' clean package', + command.script + ' clean install' + ] diff --git a/thefuck/rules/mvn_unknown_lifecycle_phase.py b/thefuck/rules/mvn_unknown_lifecycle_phase.py index fa2cf20..6c02bcc 100644 --- a/thefuck/rules/mvn_unknown_lifecycle_phase.py +++ b/thefuck/rules/mvn_unknown_lifecycle_phase.py @@ -3,13 +3,16 @@ import re def _get_failed_lifecycle(command): - return re.search(r'\[ERROR\] Unknown lifecycle phase "(.+)"', - command.output) + return re.search( + r'\[ERROR\] Unknown lifecycle phase "(.+)"', + command.output + ) def _getavailable_lifecycles(command): return re.search( - r'Available lifecycle phases are: (.+) -> \[Help 1\]', command.output) + r'Available lifecycle phases are: (.+) -> \[Help 1\]', command.output + ) @for_app('mvn') diff --git a/thefuck/rules/no_command.py b/thefuck/rules/no_command.py index 0862329..052d262 100644 --- a/thefuck/rules/no_command.py +++ b/thefuck/rules/no_command.py @@ -5,11 +5,17 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return (not which(command.script_parts[0]) - and ('not found' in command.output - or 'is not recognized as' in command.output) - and bool(get_close_matches(command.script_parts[0], - get_all_executables()))) + return ( + not which(command.script_parts[0]) + and ('not found' in command.output + or 'is not recognized as' in command.output) + and bool( + get_close_matches( + command.script_parts[0], + get_all_executables() + ) + ) + ) def _get_used_executables(command): @@ -24,16 +30,21 @@ def get_new_command(command): # One from history: already_used = get_closest( old_command, _get_used_executables(command), - fallback_to_first=False) + fallback_to_first=False + ) if already_used: new_cmds = [already_used] else: new_cmds = [] # Other from all executables: - new_cmds += [cmd for cmd in get_close_matches(old_command, - get_all_executables()) - if cmd not in new_cmds] + new_cmds += [ + cmd for cmd in get_close_matches( + old_command, + get_all_executables() + ) + if cmd not in new_cmds + ] return [command.script.replace(old_command, cmd, 1) for cmd in new_cmds] From 6a3bcbd23ae686e21e500b71ed88067678406592 Mon Sep 17 00:00:00 2001 From: DashBing Date: Mon, 21 Aug 2023 11:16:38 +0800 Subject: [PATCH 13/16] fix all of rules/* --- thefuck/rules/npm_missing_script.py | 9 +- thefuck/rules/npm_run_script.py | 6 +- thefuck/rules/npm_wrong_command.py | 8 +- thefuck/rules/omnienv_no_such_command.py | 6 +- thefuck/rules/open.py | 30 ++++--- thefuck/rules/pacman.py | 6 +- thefuck/rules/pacman_not_found.py | 12 ++- thefuck/rules/path_from_history.py | 18 ++-- thefuck/rules/php_s.py | 6 +- thefuck/rules/pip_unknown_command.py | 14 +-- thefuck/rules/port_already_in_use.py | 10 ++- thefuck/rules/prove_recursively.py | 5 +- thefuck/rules/python_command.py | 10 ++- .../react_native_command_unrecognized.py | 6 +- thefuck/rules/rm_dir.py | 6 +- thefuck/rules/rm_root.py | 6 +- thefuck/rules/sudo.py | 58 ++++++------ thefuck/rules/sudo_command_from_user_path.py | 6 +- thefuck/rules/switch_lang.py | 88 +++++++++++-------- thefuck/rules/systemctl.py | 6 +- thefuck/rules/terraform_init.py | 7 +- thefuck/rules/tmux.py | 12 ++- thefuck/rules/tsuru_login.py | 6 +- thefuck/rules/tsuru_not_command.py | 18 ++-- thefuck/rules/unknown_command.py | 6 +- thefuck/rules/vagrant_up.py | 6 +- thefuck/rules/workon_doesnt_exists.py | 12 ++- thefuck/rules/yarn_command_not_found.py | 6 +- thefuck/rules/yarn_help.py | 6 +- 29 files changed, 243 insertions(+), 152 deletions(-) diff --git a/thefuck/rules/npm_missing_script.py b/thefuck/rules/npm_missing_script.py index fc9d5a4..e0b42be 100644 --- a/thefuck/rules/npm_missing_script.py +++ b/thefuck/rules/npm_missing_script.py @@ -7,11 +7,14 @@ enabled_by_default = npm_available @for_app('npm') def match(command): - return (any(part.startswith('ru') for part in command.script_parts) - and 'npm ERR! missing script: ' in command.output) + return ( + any(part.startswith('ru') for part in command.script_parts) + and 'npm ERR! missing script: ' in command.output + ) def get_new_command(command): misspelled_script = re.findall( - r'.*missing script: (.*)\n', command.output)[0] + r'.*missing script: (.*)\n', command.output + )[0] return replace_command(command, misspelled_script, get_scripts()) diff --git a/thefuck/rules/npm_run_script.py b/thefuck/rules/npm_run_script.py index 6d932f4..0283926 100644 --- a/thefuck/rules/npm_run_script.py +++ b/thefuck/rules/npm_run_script.py @@ -6,9 +6,11 @@ enabled_by_default = npm_available @for_app('npm') def match(command): - return ('Usage: npm ' in command.output + return ( + 'Usage: npm ' in command.output and not any(part.startswith('ru') for part in command.script_parts) - and command.script_parts[1] in get_scripts()) + and command.script_parts[1] in get_scripts() + ) def get_new_command(command): diff --git a/thefuck/rules/npm_wrong_command.py b/thefuck/rules/npm_wrong_command.py index e3511fe..703509c 100644 --- a/thefuck/rules/npm_wrong_command.py +++ b/thefuck/rules/npm_wrong_command.py @@ -14,9 +14,11 @@ def _get_wrong_command(script_parts): @sudo_support @for_app('npm') def match(command): - return (command.script_parts[0] == 'npm' and - 'where is one of:' in command.output and - _get_wrong_command(command.script_parts)) + return ( + command.script_parts[0] == 'npm' and + 'where is one of:' in command.output and + _get_wrong_command(command.script_parts) + ) @eager diff --git a/thefuck/rules/omnienv_no_such_command.py b/thefuck/rules/omnienv_no_such_command.py index ca8cc36..03cf6d4 100644 --- a/thefuck/rules/omnienv_no_such_command.py +++ b/thefuck/rules/omnienv_no_such_command.py @@ -26,8 +26,10 @@ def get_app_commands(app): def get_new_command(command): broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0] - matched = [replace_argument(command.script, broken, common_typo) - for common_typo in COMMON_TYPOS.get(broken, [])] + matched = [ + replace_argument(command.script, broken, common_typo) + for common_typo in COMMON_TYPOS.get(broken, []) + ] app = command.script_parts[0] app_commands = cache(which(app))(get_app_commands)(app) diff --git a/thefuck/rules/open.py b/thefuck/rules/open.py index 1c70112..4826fbb 100644 --- a/thefuck/rules/open.py +++ b/thefuck/rules/open.py @@ -10,23 +10,27 @@ from thefuck.utils import eager, for_app def is_arg_url(command): - return ('.com' in command.script or - '.edu' in command.script or - '.info' in command.script or - '.io' in command.script or - '.ly' in command.script or - '.me' in command.script or - '.net' in command.script or - '.org' in command.script or - '.se' in command.script or - 'www.' in command.script) + return ( + '.com' in command.script or + '.edu' in command.script or + '.info' in command.script or + '.io' in command.script or + '.ly' in command.script or + '.me' in command.script or + '.net' in command.script or + '.org' in command.script or + '.se' in command.script or + 'www.' in command.script + ) @for_app('open', 'xdg-open', 'gnome-open', 'kde-open') def match(command): - return (is_arg_url(command) or - command.output.strip().startswith('The file ') and - command.output.strip().endswith(' does not exist.')) + return ( + is_arg_url(command) or + command.output.strip().startswith('The file ') and + command.output.strip().endswith(' does not exist.') + ) @eager diff --git a/thefuck/rules/pacman.py b/thefuck/rules/pacman.py index 92a48e8..86a207a 100644 --- a/thefuck/rules/pacman.py +++ b/thefuck/rules/pacman.py @@ -10,8 +10,10 @@ def get_new_command(command): packages = get_pkgfile(command.script) formatme = shell.and_('{} -S {}', '{}') - return [formatme.format(pacman, package, command.script) - for package in packages] + return [ + formatme.format(pacman, package, command.script) + for package in packages + ] enabled_by_default, pacman = archlinux_env() diff --git a/thefuck/rules/pacman_not_found.py b/thefuck/rules/pacman_not_found.py index c1ce292..2adccd6 100644 --- a/thefuck/rules/pacman_not_found.py +++ b/thefuck/rules/pacman_not_found.py @@ -11,10 +11,14 @@ from thefuck.specific.archlinux import get_pkgfile, archlinux_env def match(command): - return (command.script_parts - and (command.script_parts[0] in ('pacman', 'yay', 'pikaur', 'yaourt') - or command.script_parts[0:2] == ['sudo', 'pacman']) - and 'error: target not found:' in command.output) + return ( + command.script_parts + and ( + command.script_parts[0] in ('pacman', 'yay', 'pikaur', 'yaourt') + or command.script_parts[0:2] == ['sudo', 'pacman'] + ) + and 'error: target not found:' in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/path_from_history.py b/thefuck/rules/path_from_history.py index d05bb9a..a3d1dc1 100644 --- a/thefuck/rules/path_from_history.py +++ b/thefuck/rules/path_from_history.py @@ -6,10 +6,12 @@ from thefuck.utils import (get_valid_history_without_current, from thefuck.shells import shell -patterns = [r'no such file or directory: (.*)$', - r"cannot access '(.*)': No such file or directory", - r': (.*): No such file or directory', - r"can't cd to (.*)$"] +patterns = [ + r'no such file or directory: (.*)$', + r"cannot access '(.*)': No such file or directory", + r': (.*): No such file or directory', + r"can't cd to (.*)$" +] @memoize @@ -45,9 +47,11 @@ def get_new_command(command): destination = _get_destination(command) paths = _get_all_absolute_paths_from_history(command) - return [replace_argument(command.script, destination, path) - for path in paths if path.endswith(destination) - and Path(path).expanduser().exists()] + return [ + replace_argument(command.script, destination, path) + for path in paths if path.endswith(destination) + and Path(path).expanduser().exists() + ] priority = 800 diff --git a/thefuck/rules/php_s.py b/thefuck/rules/php_s.py index 65f5039..97901c5 100644 --- a/thefuck/rules/php_s.py +++ b/thefuck/rules/php_s.py @@ -3,8 +3,10 @@ from thefuck.utils import replace_argument, for_app @for_app('php', at_least=2) def match(command): - return ('-s' in command.script_parts - and command.script_parts[-1] != '-s') + return ( + '-s' in command.script_parts + and command.script_parts[-1] != '-s' + ) def get_new_command(command): diff --git a/thefuck/rules/pip_unknown_command.py b/thefuck/rules/pip_unknown_command.py index 2720cda..821f4f1 100644 --- a/thefuck/rules/pip_unknown_command.py +++ b/thefuck/rules/pip_unknown_command.py @@ -6,14 +6,18 @@ from thefuck.specific.sudo import sudo_support @sudo_support @for_app('pip', 'pip2', 'pip3') def match(command): - return ('pip' in command.script and - 'unknown command' in command.output and - 'maybe you meant' in command.output) + return ( + 'pip' in command.script and + 'unknown command' in command.output and + 'maybe you meant' in command.output + ) def get_new_command(command): - broken_cmd = re.findall(r'ERROR: unknown command "([^"]+)"', - command.output)[0] + broken_cmd = re.findall( + r'ERROR: unknown command "([^"]+)"', + command.output + )[0] new_cmd = re.findall(r'maybe you meant "([^"]+)"', command.output)[0] return replace_argument(command.script, broken_cmd, new_cmd) diff --git a/thefuck/rules/port_already_in_use.py b/thefuck/rules/port_already_in_use.py index d355243..7c41d54 100644 --- a/thefuck/rules/port_already_in_use.py +++ b/thefuck/rules/port_already_in_use.py @@ -5,10 +5,12 @@ from thefuck.shells import shell enabled_by_default = bool(which('lsof')) -patterns = [r"bind on address \('.*', (?P\d+)\)", - r'Unable to bind [^ ]*:(?P\d+)', - r"can't listen on port (?P\d+)", - r'listen EADDRINUSE [^ ]*:(?P\d+)'] +patterns = [ + r"bind on address \('.*', (?P\d+)\)", + r'Unable to bind [^ ]*:(?P\d+)', + r"can't listen on port (?P\d+)", + r'listen EADDRINUSE [^ ]*:(?P\d+)' +] @memoize diff --git a/thefuck/rules/prove_recursively.py b/thefuck/rules/prove_recursively.py index 224a4e6..150ea6c 100644 --- a/thefuck/rules/prove_recursively.py +++ b/thefuck/rules/prove_recursively.py @@ -17,8 +17,9 @@ def _isdir(part): def match(command): return ( 'NOTESTS' in command.output - and not any(_is_recursive(part) for part in command.script_parts[1:]) - and any(_isdir(part) for part in command.script_parts[1:])) + and not any(_is_recursive(part) for part in command.script_parts[1:]) + and any(_isdir(part) for part in command.script_parts[1:]) + ) def get_new_command(command): diff --git a/thefuck/rules/python_command.py b/thefuck/rules/python_command.py index 0869937..fa1eba4 100644 --- a/thefuck/rules/python_command.py +++ b/thefuck/rules/python_command.py @@ -6,10 +6,14 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return (command.script_parts + return ( + command.script_parts and command.script_parts[0].endswith('.py') - and ('Permission denied' in command.output or - 'command not found' in command.output)) + and ( + 'Permission denied' in command.output or + 'command not found' in command.output + ) + ) @sudo_support diff --git a/thefuck/rules/react_native_command_unrecognized.py b/thefuck/rules/react_native_command_unrecognized.py index 41a25ce..1b833dc 100644 --- a/thefuck/rules/react_native_command_unrecognized.py +++ b/thefuck/rules/react_native_command_unrecognized.py @@ -28,7 +28,9 @@ def _get_commands(): def get_new_command(command): - misspelled_command = re.findall(r"Unrecognized command '(.*)'", - command.output)[0] + misspelled_command = re.findall( + r"Unrecognized command '(.*)'", + command.output + )[0] commands = _get_commands() return replace_command(command, misspelled_command, commands) diff --git a/thefuck/rules/rm_dir.py b/thefuck/rules/rm_dir.py index 6c6449f..bad0ac3 100644 --- a/thefuck/rules/rm_dir.py +++ b/thefuck/rules/rm_dir.py @@ -4,8 +4,10 @@ from thefuck.specific.sudo import sudo_support @sudo_support def match(command): - return ('rm' in command.script - and 'is a directory' in command.output.lower()) + return ( + 'rm' in command.script + and 'is a directory' in command.output.lower() + ) @sudo_support diff --git a/thefuck/rules/rm_root.py b/thefuck/rules/rm_root.py index 3eb3047..5d5424d 100644 --- a/thefuck/rules/rm_root.py +++ b/thefuck/rules/rm_root.py @@ -5,10 +5,12 @@ enabled_by_default = False @sudo_support def match(command): - return (command.script_parts + return ( + command.script_parts and {'rm', '/'}.issubset(command.script_parts) and '--no-preserve-root' not in command.script - and '--no-preserve-root' in command.output) + and '--no-preserve-root' in command.output + ) @sudo_support diff --git a/thefuck/rules/sudo.py b/thefuck/rules/sudo.py index 0c83ba7..02dc1cb 100644 --- a/thefuck/rules/sudo.py +++ b/thefuck/rules/sudo.py @@ -1,31 +1,33 @@ -patterns = ['permission denied', - 'eacces', - 'pkg: insufficient privileges', - 'you cannot perform this operation unless you are root', - 'non-root users cannot', - 'operation not permitted', - 'not super-user', - 'superuser privilege', - 'root privilege', - 'this command has to be run under the root user.', - 'this operation requires root.', - 'requested operation requires superuser privilege', - 'must be run as root', - 'must run as root', - 'must be superuser', - 'must be root', - 'need to be root', - 'need root', - 'needs to be run as root', - 'only root can ', - 'you don\'t have access to the history db.', - 'authentication is required', - 'edspermissionerror', - 'you don\'t have write permissions', - 'use `sudo`', - 'sudorequirederror', - 'error: insufficient privileges', - 'updatedb: can not open a temporary file'] +patterns = [ + 'permission denied', + 'eacces', + 'pkg: insufficient privileges', + 'you cannot perform this operation unless you are root', + 'non-root users cannot', + 'operation not permitted', + 'not super-user', + 'superuser privilege', + 'root privilege', + 'this command has to be run under the root user.', + 'this operation requires root.', + 'requested operation requires superuser privilege', + 'must be run as root', + 'must run as root', + 'must be superuser', + 'must be root', + 'need to be root', + 'need root', + 'needs to be run as root', + 'only root can ', + 'you don\'t have access to the history db.', + 'authentication is required', + 'edspermissionerror', + 'you don\'t have write permissions', + 'use `sudo`', + 'sudorequirederror', + 'error: insufficient privileges', + 'updatedb: can not open a temporary file' +] def match(command): diff --git a/thefuck/rules/sudo_command_from_user_path.py b/thefuck/rules/sudo_command_from_user_path.py index 256f8aa..aef20b4 100644 --- a/thefuck/rules/sudo_command_from_user_path.py +++ b/thefuck/rules/sudo_command_from_user_path.py @@ -17,5 +17,7 @@ def match(command): def get_new_command(command): command_name = _get_command_name(command) - return replace_argument(command.script, command_name, - u'env "PATH=$PATH" {}'.format(command_name)) + return replace_argument( + command.script, command_name, + u'env "PATH=$PATH" {}'.format(command_name) + ) diff --git a/thefuck/rules/switch_lang.py b/thefuck/rules/switch_lang.py index 6f8d763..91d5f87 100644 --- a/thefuck/rules/switch_lang.py +++ b/thefuck/rules/switch_lang.py @@ -7,42 +7,56 @@ target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVB greek = u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?''' korean = u'''ㅂㅈㄷㄱㅅㅛㅕㅑㅐㅔ[]ㅁㄴㅇㄹㅎㅗㅓㅏㅣ;'ㅋㅌㅊㅍㅠㅜㅡ,./ㅃㅉㄸㄲㅆㅛㅕㅑㅒㅖ{}ㅁㄴㅇㄹㅎㅗㅓㅏㅣ:"ㅋㅌㅊㅍㅠㅜㅡ<>?''' -source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''', - u'''йцукенгшщзхїфівапролджєячсмитьбю.ЙЦУКЕНГШЩЗХЇФІВАПРОЛДЖЄЯЧСМИТЬБЮ,''', - u'''ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپو./ًٌٍَُِّْ][}{ؤئيإأآة»«:؛كٓژٰ‌ٔء><؟''', - u'''/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''', - greek, - korean] +source_layouts = [ + u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''', + u'''йцукенгшщзхїфівапролджєячсмитьбю.ЙЦУКЕНГШЩЗХЇФІВАПРОЛДЖЄЯЧСМИТЬБЮ,''', + u'''ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپو./ًٌٍَُِّْ][}{ؤئيإأآة»«:؛كٓژٰ‌ٔء><؟''', + u'''/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''', + greek, + korean +] source_to_target = { - greek: {u';': "q", u'ς': "w", u'ε': "e", u'ρ': "r", u'τ': "t", u'υ': "y", - u'θ': "u", u'ι': "i", u'ο': "o", u'π': "p", u'[': "[", u']': "]", - u'α': "a", u'σ': "s", u'δ': "d", u'φ': "f", u'γ': "g", u'η': "h", - u'ξ': "j", u'κ': "k", u'λ': "l", u'΄': "'", u'ζ': "z", u'χ': "x", - u'ψ': "c", u'ω': "v", u'β': "b", u'ν': "n", u'μ': "m", u',': ",", - u'.': ".", u'/': "/", u':': "Q", u'΅': "W", u'Ε': "E", u'Ρ': "R", - u'Τ': "T", u'Υ': "Y", u'Θ': "U", u'Ι': "I", u'Ο': "O", u'Π': "P", - u'{': "{", u'}': "}", u'Α': "A", u'Σ': "S", u'Δ': "D", u'Φ': "F", - u'Γ': "G", u'Η': "H", u'Ξ': "J", u'Κ': "K", u'Λ': "L", u'¨': ":", - u'"': '"', u'Ζ': "Z", u'Χ': "X", u'Ψ': "C", u'Ω': "V", u'Β': "B", - u'Ν': "N", u'Μ': "M", u'<': "<", u'>': ">", u'?': "?", u'ά': "a", - u'έ': "e", u'ύ': "y", u'ί': "i", u'ό': "o", u'ή': 'h', u'ώ': u"v", - u'Ά': "A", u'Έ': "E", u'Ύ': "Y", u'Ί': "I", u'Ό': "O", u'Ή': "H", - u'Ώ': "V"}, + greek: { + u';': "q", u'ς': "w", u'ε': "e", u'ρ': "r", u'τ': "t", u'υ': "y", + u'θ': "u", u'ι': "i", u'ο': "o", u'π': "p", u'[': "[", u']': "]", + u'α': "a", u'σ': "s", u'δ': "d", u'φ': "f", u'γ': "g", u'η': "h", + u'ξ': "j", u'κ': "k", u'λ': "l", u'΄': "'", u'ζ': "z", u'χ': "x", + u'ψ': "c", u'ω': "v", u'β': "b", u'ν': "n", u'μ': "m", u',': ",", + u'.': ".", u'/': "/", u':': "Q", u'΅': "W", u'Ε': "E", u'Ρ': "R", + u'Τ': "T", u'Υ': "Y", u'Θ': "U", u'Ι': "I", u'Ο': "O", u'Π': "P", + u'{': "{", u'}': "}", u'Α': "A", u'Σ': "S", u'Δ': "D", u'Φ': "F", + u'Γ': "G", u'Η': "H", u'Ξ': "J", u'Κ': "K", u'Λ': "L", u'¨': ":", + u'"': '"', u'Ζ': "Z", u'Χ': "X", u'Ψ': "C", u'Ω': "V", u'Β': "B", + u'Ν': "N", u'Μ': "M", u'<': "<", u'>': ">", u'?': "?", u'ά': "a", + u'έ': "e", u'ύ': "y", u'ί': "i", u'ό': "o", u'ή': 'h', u'ώ': u"v", + u'Ά': "A", u'Έ': "E", u'Ύ': "Y", u'Ί': "I", u'Ό': "O", u'Ή': "H", + u'Ώ': "V" + }, } '''Lists used for decomposing korean letters.''' -HEAD_LIST = [u'ㄱ', u'ㄲ', u'ㄴ', u'ㄷ', u'ㄸ', u'ㄹ', u'ㅁ', u'ㅂ', u'ㅃ', u'ㅅ', u'ㅆ', - u'ㅇ', u'ㅈ', u'ㅉ', u'ㅊ', u'ㅋ', u'ㅌ', u'ㅍ', u'ㅎ'] -BODY_LIST = [u'ㅏ', u'ㅐ', u'ㅑ', u'ㅒ', u'ㅓ', u'ㅔ', u'ㅕ', u'ㅖ', u'ㅗ', u'ㅘ', u'ㅙ', - u'ㅚ', u'ㅛ', u'ㅜ', u'ㅝ', u'ㅞ', u'ㅟ', u'ㅠ', u'ㅡ', u'ㅢ', u'ㅣ'] -TAIL_LIST = [u' ', u'ㄱ', u'ㄲ', u'ㄳ', u'ㄴ', u'ㄵ', u'ㄶ', u'ㄷ', u'ㄹ', u'ㄺ', u'ㄻ', - u'ㄼ', u'ㄽ', u'ㄾ', u'ㄿ', u'ㅀ', u'ㅁ', u'ㅂ', u'ㅄ', u'ㅅ', u'ㅆ', u'ㅇ', u'ㅈ', - u'ㅊ', u'ㅋ', u'ㅌ', u'ㅍ', u'ㅎ'] -DOUBLE_LIST = [u'ㅘ', u'ㅙ', u'ㅚ', u'ㅝ', u'ㅞ', u'ㅟ', u'ㅢ', u'ㄳ', u'ㄵ', u'ㄶ', u'ㄺ', - u'ㄻ', u'ㄼ', u'ㄽ', u'ㄾ', u'ㅀ', u'ㅄ'] -DOUBLE_MOD_LIST = [u'ㅗㅏ', u'ㅗㅐ', u'ㅗㅣ', u'ㅜㅓ', u'ㅜㅔ', u'ㅜㅣ', u'ㅡㅣ', u'ㄱㅅ', - u'ㄴㅈ', u'ㄴㅎ', u'ㄹㄱ', u'ㄹㅁ', u'ㄹㅂ', u'ㄹㅅ', u'ㄹㅌ', u'ㄹㅎ', u'ㅂㅅ'] +HEAD_LIST = [ + u'ㄱ', u'ㄲ', u'ㄴ', u'ㄷ', u'ㄸ', u'ㄹ', u'ㅁ', u'ㅂ', u'ㅃ', u'ㅅ', u'ㅆ', + u'ㅇ', u'ㅈ', u'ㅉ', u'ㅊ', u'ㅋ', u'ㅌ', u'ㅍ', u'ㅎ' +] +BODY_LIST = [ + u'ㅏ', u'ㅐ', u'ㅑ', u'ㅒ', u'ㅓ', u'ㅔ', u'ㅕ', u'ㅖ', u'ㅗ', u'ㅘ', u'ㅙ', + u'ㅚ', u'ㅛ', u'ㅜ', u'ㅝ', u'ㅞ', u'ㅟ', u'ㅠ', u'ㅡ', u'ㅢ', u'ㅣ' +] +TAIL_LIST = [ + u' ', u'ㄱ', u'ㄲ', u'ㄳ', u'ㄴ', u'ㄵ', u'ㄶ', u'ㄷ', u'ㄹ', u'ㄺ', u'ㄻ', + u'ㄼ', u'ㄽ', u'ㄾ', u'ㄿ', u'ㅀ', u'ㅁ', u'ㅂ', u'ㅄ', u'ㅅ', u'ㅆ', u'ㅇ', u'ㅈ', + u'ㅊ', u'ㅋ', u'ㅌ', u'ㅍ', u'ㅎ' +] +DOUBLE_LIST = [ + u'ㅘ', u'ㅙ', u'ㅚ', u'ㅝ', u'ㅞ', u'ㅟ', u'ㅢ', u'ㄳ', u'ㄵ', u'ㄶ', u'ㄺ', + u'ㄻ', u'ㄼ', u'ㄽ', u'ㄾ', u'ㅀ', u'ㅄ' +] +DOUBLE_MOD_LIST = [ + u'ㅗㅏ', u'ㅗㅐ', u'ㅗㅣ', u'ㅜㅓ', u'ㅜㅔ', u'ㅜㅣ', u'ㅡㅣ', u'ㄱㅅ', + u'ㄴㅈ', u'ㄴㅎ', u'ㄹㄱ', u'ㄹㅁ', u'ㄹㅂ', u'ㄹㅅ', u'ㄹㅌ', u'ㄹㅎ', u'ㅂㅅ' +] @memoize @@ -70,8 +84,10 @@ def _switch(ch, layout): def _switch_command(command, layout): # Layouts with different amount of characters than English if layout in source_to_target: - return ''.join(source_to_target[layout].get(ch, ch) - for ch in command.script) + return ''.join( + source_to_target[layout].get(ch, ch) + for ch in command.script + ) return ''.join(_switch(ch, layout) for ch in command.script) @@ -105,8 +121,10 @@ def match(command): return True matched_layout = _get_matched_layout(command) - return (matched_layout and - _switch_command(command, matched_layout) != get_alias()) + return ( + matched_layout and + _switch_command(command, matched_layout) != get_alias() + ) def get_new_command(command): diff --git a/thefuck/rules/systemctl.py b/thefuck/rules/systemctl.py index 3968819..daef807 100644 --- a/thefuck/rules/systemctl.py +++ b/thefuck/rules/systemctl.py @@ -11,8 +11,10 @@ def match(command): # Catches "Unknown operation 'service'." when executing systemctl with # misordered arguments cmd = command.script_parts - return (cmd and 'Unknown operation \'' in command.output and - len(cmd) - cmd.index('systemctl') == 3) + return ( + cmd and 'Unknown operation \'' in command.output and + len(cmd) - cmd.index('systemctl') == 3 + ) @sudo_support diff --git a/thefuck/rules/terraform_init.py b/thefuck/rules/terraform_init.py index 29dd44f..7e97888 100644 --- a/thefuck/rules/terraform_init.py +++ b/thefuck/rules/terraform_init.py @@ -4,9 +4,10 @@ from thefuck.utils import for_app @for_app('terraform') def match(command): - return ('this module is not yet installed' in command.output.lower() or - 'initialization required' in command.output.lower() - ) + return ( + 'this module is not yet installed' in command.output.lower() or + 'initialization required' in command.output.lower() + ) def get_new_command(command): diff --git a/thefuck/rules/tmux.py b/thefuck/rules/tmux.py index b7f9b01..971ec18 100644 --- a/thefuck/rules/tmux.py +++ b/thefuck/rules/tmux.py @@ -4,13 +4,17 @@ from thefuck.utils import replace_command, for_app @for_app('tmux') def match(command): - return ('ambiguous command:' in command.output - and 'could be:' in command.output) + return ( + 'ambiguous command:' in command.output + and 'could be:' in command.output + ) def get_new_command(command): - cmd = re.match(r"ambiguous command: (.*), could be: (.*)", - command.output) + cmd = re.match( + r"ambiguous command: (.*), could be: (.*)", + command.output + ) old_cmd = cmd.group(1) suggestions = [c.strip() for c in cmd.group(2).split(',')] diff --git a/thefuck/rules/tsuru_login.py b/thefuck/rules/tsuru_login.py index e2a5ef8..996fd63 100644 --- a/thefuck/rules/tsuru_login.py +++ b/thefuck/rules/tsuru_login.py @@ -4,8 +4,10 @@ from thefuck.utils import for_app @for_app('tsuru') def match(command): - return ('not authenticated' in command.output - and 'session has expired' in command.output) + return ( + 'not authenticated' in command.output + and 'session has expired' in command.output + ) def get_new_command(command): diff --git a/thefuck/rules/tsuru_not_command.py b/thefuck/rules/tsuru_not_command.py index 2535104..e0d62f5 100644 --- a/thefuck/rules/tsuru_not_command.py +++ b/thefuck/rules/tsuru_not_command.py @@ -4,12 +4,18 @@ from thefuck.utils import get_all_matched_commands, replace_command, for_app @for_app('tsuru') def match(command): - return (' is not a tsuru command. See "tsuru help".' in command.output - and '\nDid you mean?\n\t' in command.output) + return ( + ' is not a tsuru command. See "tsuru help".' in command.output + and '\nDid you mean?\n\t' in command.output + ) def get_new_command(command): - broken_cmd = re.findall(r'tsuru: "([^"]*)" is not a tsuru command', - command.output)[0] - return replace_command(command, broken_cmd, - get_all_matched_commands(command.output)) + broken_cmd = re.findall( + r'tsuru: "([^"]*)" is not a tsuru command', + command.output + )[0] + return replace_command( + command, broken_cmd, + get_all_matched_commands(command.output) + ) diff --git a/thefuck/rules/unknown_command.py b/thefuck/rules/unknown_command.py index 7deaf2a..96972c9 100644 --- a/thefuck/rules/unknown_command.py +++ b/thefuck/rules/unknown_command.py @@ -3,8 +3,10 @@ from thefuck.utils import replace_command def match(command): - return (re.search(r"([^:]*): Unknown command.*", command.output) is not None - and re.search(r"Did you mean ([^?]*)?", command.output) is not None) + return ( + re.search(r"([^:]*): Unknown command.*", command.output) is not None + and re.search(r"Did you mean ([^?]*)?", command.output) is not None + ) def get_new_command(command): diff --git a/thefuck/rules/vagrant_up.py b/thefuck/rules/vagrant_up.py index 68783ff..d2dc17e 100644 --- a/thefuck/rules/vagrant_up.py +++ b/thefuck/rules/vagrant_up.py @@ -17,5 +17,7 @@ def get_new_command(command): if machine is None: return start_all_instances else: - return [shell.and_(u"vagrant up {}".format(machine), command.script), - start_all_instances] + return [ + shell.and_(u"vagrant up {}".format(machine), command.script), + start_all_instances + ] diff --git a/thefuck/rules/workon_doesnt_exists.py b/thefuck/rules/workon_doesnt_exists.py index 41d17c0..8d17d5e 100644 --- a/thefuck/rules/workon_doesnt_exists.py +++ b/thefuck/rules/workon_doesnt_exists.py @@ -16,8 +16,10 @@ def _get_all_environments(): @for_app('workon') def match(command): - return (len(command.script_parts) >= 2 - and command.script_parts[1] not in _get_all_environments()) + return ( + len(command.script_parts) >= 2 + and command.script_parts[1] not in _get_all_environments() + ) def get_new_command(command): @@ -26,7 +28,9 @@ def get_new_command(command): available = _get_all_environments() if available: - return (replace_command(command, misspelled_env, available) - + [create_new]) + return ( + replace_command(command, misspelled_env, available) + + [create_new] + ) else: return create_new diff --git a/thefuck/rules/yarn_command_not_found.py b/thefuck/rules/yarn_command_not_found.py index 9150775..93a8052 100644 --- a/thefuck/rules/yarn_command_not_found.py +++ b/thefuck/rules/yarn_command_not_found.py @@ -1,7 +1,9 @@ import re from subprocess import Popen, PIPE -from thefuck.utils import (for_app, eager, replace_command, replace_argument, - cache, which) +from thefuck.utils import ( + for_app, eager, replace_command, replace_argument, + cache, which +) regex = re.compile(r'error Command "(.*)" not found.') diff --git a/thefuck/rules/yarn_help.py b/thefuck/rules/yarn_help.py index 6c360dd..f03c2fa 100644 --- a/thefuck/rules/yarn_help.py +++ b/thefuck/rules/yarn_help.py @@ -5,8 +5,10 @@ from thefuck.system import open_command @for_app('yarn', at_least=2) def match(command): - return (command.script_parts[1] == 'help' - and 'for documentation about this command.' in command.output) + return ( + command.script_parts[1] == 'help' + and 'for documentation about this command.' in command.output + ) def get_new_command(command): From 752aa6af5b00a423a295b99d585944c8d81555c8 Mon Sep 17 00:00:00 2001 From: DashBing Date: Mon, 21 Aug 2023 11:21:54 +0800 Subject: [PATCH 14/16] fix all thefuck/* --- thefuck/entrypoints/alias.py | 6 ++++-- thefuck/entrypoints/main.py | 6 ++++-- thefuck/entrypoints/not_configured.py | 16 +++++++++++----- thefuck/output_readers/rerun.py | 20 ++++++++++++++------ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/thefuck/entrypoints/alias.py b/thefuck/entrypoints/alias.py index c7094d4..216d5f8 100644 --- a/thefuck/entrypoints/alias.py +++ b/thefuck/entrypoints/alias.py @@ -7,8 +7,10 @@ from ..utils import which def _get_alias(known_args): if six.PY2: - warn("The Fuck will drop Python 2 support soon, more details " - "https://github.com/nvbn/thefuck/issues/685") + warn( + "The Fuck will drop Python 2 support soon, more details " + "https://github.com/nvbn/thefuck/issues/685" + ) alias = shell.app_alias(known_args.alias) diff --git a/thefuck/entrypoints/main.py b/thefuck/entrypoints/main.py index 856a3d2..692d4b6 100644 --- a/thefuck/entrypoints/main.py +++ b/thefuck/entrypoints/main.py @@ -20,8 +20,10 @@ def main(): if known_args.help: parser.print_help() elif known_args.version: - logs.version(get_installation_version(), - sys.version.split()[0], shell.info()) + logs.version( + get_installation_version(), + sys.version.split()[0], shell.info() + ) # It's important to check if an alias is being requested before checking if # `TF_HISTORY` is in `os.environ`, otherwise it might mess with subshells. # Check https://github.com/nvbn/thefuck/issues/921 for reference diff --git a/thefuck/entrypoints/not_configured.py b/thefuck/entrypoints/not_configured.py index f5d7e85..001cc70 100644 --- a/thefuck/entrypoints/not_configured.py +++ b/thefuck/entrypoints/not_configured.py @@ -28,9 +28,13 @@ def _get_shell_pid(): def _get_not_configured_usage_tracker_path(): """Returns path of special file where we store latest shell pid.""" - return Path(gettempdir()).joinpath(u'thefuck.last_not_configured_run_{}'.format( - getpass.getuser(), - )) + return ( + Path(gettempdir()).joinpath( + u'thefuck.last_not_configured_run_{}'.format( + getpass.getuser(), + ) + ) + ) def _record_first_run(): @@ -68,8 +72,10 @@ def _is_second_run(): if not (isinstance(info, dict) and info.get('pid') == current_pid): return False - return (_get_previous_command() == 'fuck' or - time.time() - info.get('time', 0) < const.CONFIGURATION_TIMEOUT) + return ( + _get_previous_command() == 'fuck' or + time.time() - info.get('time', 0) < const.CONFIGURATION_TIMEOUT + ) def _is_already_configured(configuration_details): diff --git a/thefuck/output_readers/rerun.py b/thefuck/output_readers/rerun.py index b7ffe24..6be2d73 100644 --- a/thefuck/output_readers/rerun.py +++ b/thefuck/output_readers/rerun.py @@ -17,8 +17,11 @@ def _kill_process(proc): try: proc.kill() except AccessDenied: - logs.debug(u'Rerun: process PID {} ({}) could not be terminated'.format( - proc.pid, proc.exe())) + logs.debug( + u'Rerun: process PID {} ({}) could not be terminated'.format( + proc.pid, proc.exe() + ) + ) def _wait_output(popen, is_slow): @@ -33,8 +36,10 @@ def _wait_output(popen, is_slow): """ proc = Process(popen.pid) try: - proc.wait(settings.wait_slow_command if is_slow - else settings.wait_command) + proc.wait( + settings.wait_slow_command if is_slow + else settings.wait_command + ) return True except TimeoutExpired: for child in proc.children(recursive=True): @@ -59,8 +64,11 @@ def get_output(script, expanded): split_expand = shlex.split(expanded) is_slow = split_expand[0] in settings.slow_commands if split_expand else False - with logs.debug_time(u'Call: {}; with env: {}; is slow: {}'.format( - script, env, is_slow)): + with logs.debug_time( + u'Call: {}; with env: {}; is slow: {}'.format( + script, env, is_slow + ) + ): result = Popen(expanded, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=env) if _wait_output(result, is_slow): From c469919246320db749c2242b64afd121e9d32d78 Mon Sep 17 00:00:00 2001 From: DashBing Date: Mon, 21 Aug 2023 11:26:34 +0800 Subject: [PATCH 15/16] fix all tests/entrypoints/* --- tests/entrypoints/test_alias.py | 16 ++++++++---- tests/entrypoints/test_fix_command.py | 20 +++++++++----- tests/entrypoints/test_not_configured.py | 33 ++++++++++++++++-------- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/tests/entrypoints/test_alias.py b/tests/entrypoints/test_alias.py index ddb13e1..97926f7 100644 --- a/tests/entrypoints/test_alias.py +++ b/tests/entrypoints/test_alias.py @@ -4,23 +4,29 @@ from thefuck.entrypoints.alias import _get_alias, print_alias @pytest.mark.parametrize( - 'py2, enable_experimental_instant_mode, which, is_instant', [ + 'py2, enable_experimental_instant_mode, which, is_instant', + [ (False, True, True, True), (False, False, True, False), (False, True, False, False), (True, True, True, False), (True, True, False, False), - (True, False, True, False)]) + (True, False, True, False) + ] +) def test_get_alias(monkeypatch, mocker, py2, enable_experimental_instant_mode, which, is_instant): monkeypatch.setattr('six.PY2', py2) args = Mock( enable_experimental_instant_mode=enable_experimental_instant_mode, - alias='fuck', ) + alias='fuck', + ) mocker.patch('thefuck.entrypoints.alias.which', return_value=which) - shell = Mock(app_alias=lambda _: 'app_alias', - instant_mode_alias=lambda _: 'instant_mode_alias') + shell = Mock( + app_alias=lambda _: 'app_alias', + instant_mode_alias=lambda _: 'instant_mode_alias' + ) monkeypatch.setattr('thefuck.entrypoints.alias.shell', shell) alias = _get_alias(args) diff --git a/tests/entrypoints/test_fix_command.py b/tests/entrypoints/test_fix_command.py index 3012bb4..96ce736 100644 --- a/tests/entrypoints/test_fix_command.py +++ b/tests/entrypoints/test_fix_command.py @@ -10,15 +10,21 @@ class TestGetRawCommand(object): def test_from_command_argument(self, os_environ): os_environ['TF_HISTORY'] = None - known_args = Mock(force_command=None, - command=['sl']) + known_args = Mock( + force_command=None, + command=['sl'] + ) assert _get_raw_command(known_args) == ['sl'] - @pytest.mark.parametrize('history, result', [ - ('git br', 'git br'), - ('git br\nfcuk', 'git br'), - ('git br\nfcuk\nls', 'ls'), - ('git br\nfcuk\nls\nfuk', 'ls')]) + @pytest.mark.parametrize( + 'history, result', + [ + ('git br', 'git br'), + ('git br\nfcuk', 'git br'), + ('git br\nfcuk\nls', 'ls'), + ('git br\nfcuk\nls\nfuk', 'ls') + ] + ) def test_from_history(self, os_environ, history, result): os_environ['TF_HISTORY'] = history known_args = Mock(force_command=None, diff --git a/tests/entrypoints/test_not_configured.py b/tests/entrypoints/test_not_configured.py index 79ed29f..848d1d6 100644 --- a/tests/entrypoints/test_not_configured.py +++ b/tests/entrypoints/test_not_configured.py @@ -10,7 +10,8 @@ from thefuck.entrypoints.not_configured import main def usage_tracker(mocker): return mocker.patch( 'thefuck.entrypoints.not_configured._get_not_configured_usage_tracker_path', - new_callable=MagicMock) + new_callable=MagicMock + ) @pytest.fixture(autouse=True) @@ -44,27 +45,34 @@ def _change_tracker(usage_tracker_io, pid): @pytest.fixture(autouse=True) def shell_pid(mocker): - return mocker.patch('thefuck.entrypoints.not_configured._get_shell_pid', - new_callable=MagicMock) + return mocker.patch( + 'thefuck.entrypoints.not_configured._get_shell_pid', + new_callable=MagicMock + ) @pytest.fixture(autouse=True) def shell(mocker): - shell = mocker.patch('thefuck.entrypoints.not_configured.shell', - new_callable=MagicMock) + shell = mocker.patch( + 'thefuck.entrypoints.not_configured.shell', + new_callable=MagicMock + ) shell.get_history.return_value = [] shell.how_to_configure.return_value = ShellConfiguration( content='eval $(thefuck --alias)', path='/tmp/.bashrc', reload='bash', - can_configure_automatically=True) + can_configure_automatically=True + ) return shell @pytest.fixture(autouse=True) def shell_config(mocker): - path_mock = mocker.patch('thefuck.entrypoints.not_configured.Path', - new_callable=MagicMock) + path_mock = mocker.patch( + 'thefuck.entrypoints.not_configured.Path', + new_callable=MagicMock + ) return path_mock.return_value \ .expanduser.return_value \ .open.return_value \ @@ -73,8 +81,10 @@ def shell_config(mocker): @pytest.fixture(autouse=True) def logs(mocker): - return mocker.patch('thefuck.entrypoints.not_configured.logs', - new_callable=MagicMock) + return mocker.patch( + 'thefuck.entrypoints.not_configured.logs', + new_callable=MagicMock + ) def test_for_generic_shell(shell, logs): @@ -114,7 +124,8 @@ def test_when_cant_configure_automatically(shell_pid, shell, logs): content='eval $(thefuck --alias)', path='/tmp/.bashrc', reload='bash', - can_configure_automatically=False) + can_configure_automatically=False + ) main() logs.how_to_configure_alias.assert_called_once() From ae13a1501ba36ae198b061dbfb1ad3ada93f3f23 Mon Sep 17 00:00:00 2001 From: DashBing Date: Mon, 21 Aug 2023 11:28:30 +0800 Subject: [PATCH 16/16] fix all tests/functional/* --- tests/functional/plots.py | 4 +++- tests/functional/test_bash.py | 20 +++++++++++++------- tests/functional/test_zsh.py | 3 ++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/functional/plots.py b/tests/functional/plots.py index 60c68a7..1e7cccb 100644 --- a/tests/functional/plots.py +++ b/tests/functional/plots.py @@ -2,7 +2,9 @@ def _set_confirmation(proc, require): proc.sendline(u'mkdir -p ~/.thefuck') proc.sendline( u'echo "require_confirmation = {}" > ~/.thefuck/settings.py'.format( - require)) + require + ) + ) def with_confirmation(proc, TIMEOUT): diff --git a/tests/functional/test_bash.py b/tests/functional/test_bash.py index 489ca25..c87cc29 100644 --- a/tests/functional/test_bash.py +++ b/tests/functional/test_bash.py @@ -4,13 +4,17 @@ from tests.functional.plots import with_confirmation, without_confirmation, \ select_command_with_arrows, how_to_configure -python_3 = (u'thefuck/python3', - u'', - u'sh') +python_3 = ( + u'thefuck/python3', + u'', + u'sh' +) -python_2 = (u'thefuck/python2', - u'', - u'sh') +python_2 = ( + u'thefuck/python2', + u'', + u'sh' +) init_bashrc = u'''echo ' @@ -29,7 +33,9 @@ def proc(request, spawnu, TIMEOUT): container, instant_mode = request.param proc = spawnu(*container) proc.sendline(init_bashrc.format( - u'--enable-experimental-instant-mode' if instant_mode else '')) + u'--enable-experimental-instant-mode' if instant_mode else '' + ) + ) proc.sendline(u"bash") if instant_mode: assert proc.expect([TIMEOUT, u'instant mode ready: True']) diff --git a/tests/functional/test_zsh.py b/tests/functional/test_zsh.py index a6c2733..d61a558 100644 --- a/tests/functional/test_zsh.py +++ b/tests/functional/test_zsh.py @@ -27,7 +27,8 @@ def proc(request, spawnu, TIMEOUT): container, instant_mode = request.param proc = spawnu(*container) proc.sendline(init_zshrc.format( - u'--enable-experimental-instant-mode' if instant_mode else '')) + u'--enable-experimental-instant-mode' if instant_mode else '') + ) proc.sendline(u"zsh") if instant_mode: assert proc.expect([TIMEOUT, u'instant mode ready: True'])