1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 06:38:32 +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):
"""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)

View File

@ -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)))

View File

@ -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