diff --git a/thefuck/entrypoints/fix_command.py b/thefuck/entrypoints/fix_command.py index 9888142f..47e9856d 100644 --- a/thefuck/entrypoints/fix_command.py +++ b/thefuck/entrypoints/fix_command.py @@ -29,6 +29,7 @@ def _get_raw_command(known_args): def fix_command(known_args): """Fixes previous command. Used when `thefuck` called without arguments.""" settings.init(known_args) + double_check_commands = {"reboot": "reboot system?"} with logs.debug_time('Total'): logs.debug(u'Run with settings: {}'.format(pformat(settings))) raw_command = _get_raw_command(known_args) @@ -43,8 +44,8 @@ def fix_command(known_args): selected_command = select_command(corrected_commands) confirmation = True - if selected_command.script == "reboot": - confirmation = confirm_command("Reboot System?") + if selected_command.script in double_check_commands: + confirmation = confirm_command(double_check_commands[selected_command.script]) if selected_command and confirmation: selected_command.run(command) diff --git a/thefuck/logs.py b/thefuck/logs.py index d5c4cbb1..7c1bd3dd 100644 --- a/thefuck/logs.py +++ b/thefuck/logs.py @@ -57,20 +57,33 @@ def show_corrected_command(corrected_command): 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))) - + if corrected_command.script != 'reboot system?': + 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))) + else: + sys.stderr.write( + (u'{prefix}{clear}{bold}{script}{reset}{side_effect} ' + u'[{green}enter{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))) def debug(msg): if settings.debug: @@ -141,12 +154,14 @@ def version(thefuck_version, python_version, shell_info): shell_info)) -def confirmation(confirm): +def confirmation(confirm, msg): if confirm is True: - sys.stderr.write(u"\n{bold}System Rebooting!\n{reset}".format( + sys.stderr.write(u"\n{bold}System will now {message}\n{reset}".format( bold=color(colorama.Style.BRIGHT), + message=msg[:-1], reset=color(colorama.Style.RESET_ALL))) else: - sys.stderr.write(u"\n{bold}Reboot Cancelled{reset}\n".format( + sys.stderr.write(u"\n{bold}{message} cancelled{reset}\n".format( bold=color(colorama.Style.BRIGHT), + message=msg[:-1], reset=color(colorama.Style.RESET_ALL))) diff --git a/thefuck/ui.py b/thefuck/ui.py index 0ddc14cf..b3813437 100644 --- a/thefuck/ui.py +++ b/thefuck/ui.py @@ -113,8 +113,8 @@ def confirm_command(confirmation_text): action = read_actions() for action in read_actions(): if action == const.ACTION_SELECT: - logs.confirmation(True) + logs.confirmation(True, confirmation_text) return True elif action == const.ACTION_ABORT: - logs.confirmation(False) + logs.confirmation(False, confirmation_text) return False