Skip to content

Instantly share code, notes, and snippets.

@Alveel
Last active May 31, 2023 12:03
Show Gist options
  • Save Alveel/3888bc584ee6c9eae647dc4590c55aa9 to your computer and use it in GitHub Desktop.
Save Alveel/3888bc584ee6c9eae647dc4590c55aa9 to your computer and use it in GitHub Desktop.
The Fuck match multiple suggestions
import re
from thefuck.utils import get_all_matched_commands, replace_command, for_app
supported_cmds = 'kubectl', 'oc'
@for_app(*supported_cmds, at_least=1)
def match(command):
return ("error: unknown command" in command.output and
"Did you mean this?" in command.output)
def get_new_command(command):
broken_cmd = re.findall("error: unknown command \"([^\"]*)\" for", command.output)[0]
fixed_cmds = get_all_matched_commands(command.output, "Did you mean this?")
return replace_command(command, broken_cmd, fixed_cmds)
enabled_by_default = True

Purposefully mistype "get"

~
➜ k ge po
error: unknown command "ge" for "kubectl"

Did you mean this?
	set
	get
	cp

~ 
✗  fuck
kubectl get pods [enter/↑/↓/ctrl+c]

get is the only suggestion we got, even though there are three? Arrow up/down doesn't change the output. Even stranger, get` isn't even the first suggestion.

This does work for git...

I'm not seeing what I'm effectively doing differently.

fuck is from The Fuck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment