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:
parent
6f99e2ea7f
commit
abd8800a92
@ -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)
|
||||||
|
@ -57,6 +57,7 @@ def show_corrected_command(corrected_command):
|
|||||||
|
|
||||||
|
|
||||||
def confirm_text(corrected_command):
|
def confirm_text(corrected_command):
|
||||||
|
if corrected_command.script != 'reboot system?':
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
(u'{prefix}{clear}{bold}{script}{reset}{side_effect} '
|
(u'{prefix}{clear}{bold}{script}{reset}{side_effect} '
|
||||||
u'[{green}enter{reset}/{blue}↑{reset}/{blue}↓{reset}'
|
u'[{green}enter{reset}/{blue}↑{reset}/{blue}↓{reset}'
|
||||||
@ -70,7 +71,19 @@ def confirm_text(corrected_command):
|
|||||||
red=color(colorama.Fore.RED),
|
red=color(colorama.Fore.RED),
|
||||||
reset=color(colorama.Style.RESET_ALL),
|
reset=color(colorama.Style.RESET_ALL),
|
||||||
blue=color(colorama.Fore.BLUE)))
|
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)))
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user