1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-20 17:48:41 +00:00

made it more extensible by adding a dictionary called double_check_commands that can be easily added to. Also remove selection arrows from prompt when asking for second confirmation

This commit is contained in:
ICalhoun 2021-04-05 19:40:29 -04:00
parent 6f99e2ea7f
commit abd8800a92
3 changed files with 37 additions and 21 deletions

View File

@ -29,6 +29,7 @@ def _get_raw_command(known_args):
def fix_command(known_args): def fix_command(known_args):
"""Fixes previous command. Used when `thefuck` called without arguments.""" """Fixes previous command. Used when `thefuck` called without arguments."""
settings.init(known_args) settings.init(known_args)
double_check_commands = {"reboot": "reboot system?"}
with logs.debug_time('Total'): with logs.debug_time('Total'):
logs.debug(u'Run with settings: {}'.format(pformat(settings))) logs.debug(u'Run with settings: {}'.format(pformat(settings)))
raw_command = _get_raw_command(known_args) raw_command = _get_raw_command(known_args)
@ -43,8 +44,8 @@ def fix_command(known_args):
selected_command = select_command(corrected_commands) selected_command = select_command(corrected_commands)
confirmation = True confirmation = True
if selected_command.script == "reboot": if selected_command.script in double_check_commands:
confirmation = confirm_command("Reboot System?") confirmation = confirm_command(double_check_commands[selected_command.script])
if selected_command and confirmation: if selected_command and confirmation:
selected_command.run(command) selected_command.run(command)

View File

@ -57,20 +57,33 @@ def show_corrected_command(corrected_command):
def confirm_text(corrected_command): def confirm_text(corrected_command):
sys.stderr.write( if corrected_command.script != 'reboot system?':
(u'{prefix}{clear}{bold}{script}{reset}{side_effect} ' sys.stderr.write(
u'[{green}enter{reset}/{blue}{reset}/{blue}{reset}' (u'{prefix}{clear}{bold}{script}{reset}{side_effect} '
u'/{red}ctrl+c{reset}]').format( u'[{green}enter{reset}/{blue}{reset}/{blue}{reset}'
prefix=const.USER_COMMAND_MARK, u'/{red}ctrl+c{reset}]').format(
script=corrected_command.script, prefix=const.USER_COMMAND_MARK,
side_effect=' (+side effect)' if corrected_command.side_effect else '', script=corrected_command.script,
clear='\033[1K\r', side_effect=' (+side effect)' if corrected_command.side_effect else '',
bold=color(colorama.Style.BRIGHT), clear='\033[1K\r',
green=color(colorama.Fore.GREEN), bold=color(colorama.Style.BRIGHT),
red=color(colorama.Fore.RED), green=color(colorama.Fore.GREEN),
reset=color(colorama.Style.RESET_ALL), red=color(colorama.Fore.RED),
blue=color(colorama.Fore.BLUE))) 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): def debug(msg):
if settings.debug: if settings.debug:
@ -141,12 +154,14 @@ def version(thefuck_version, python_version, shell_info):
shell_info)) shell_info))
def confirmation(confirm): def confirmation(confirm, msg):
if confirm is True: 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), bold=color(colorama.Style.BRIGHT),
message=msg[:-1],
reset=color(colorama.Style.RESET_ALL))) reset=color(colorama.Style.RESET_ALL)))
else: 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), bold=color(colorama.Style.BRIGHT),
message=msg[:-1],
reset=color(colorama.Style.RESET_ALL))) reset=color(colorama.Style.RESET_ALL)))

View File

@ -113,8 +113,8 @@ def confirm_command(confirmation_text):
action = read_actions() action = read_actions()
for action in read_actions(): for action in read_actions():
if action == const.ACTION_SELECT: if action == const.ACTION_SELECT:
logs.confirmation(True) logs.confirmation(True, confirmation_text)
return True return True
elif action == const.ACTION_ABORT: elif action == const.ACTION_ABORT:
logs.confirmation(False) logs.confirmation(False, confirmation_text)
return False return False