Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about adding a typo correction rule related to 'nvm'? #1421

Open
An-JiYun opened this issue Nov 29, 2023 · 0 comments
Open

How about adding a typo correction rule related to 'nvm'? #1421

An-JiYun opened this issue Nov 29, 2023 · 0 comments

Comments

@An-JiYun
Copy link

The output of thefuck --version :

The Fuck 3.32 using Python 3.8.10 and Bash 5.0.17(1)-release

Your system (Debian 7, ArchLinux, Windows, etc.):

Linux version 5.15.133.1-microsoft-standard-WSL2 (root@1c602f52c2e4) (gcc (GCC) 11.2.0, GNU ld (GNU Binutils) 2.37) #1 SMP Thu Oct 5 21:02:42 UTC 2023

How to reproduce the bug:

1. Enter a command with a typo in the "nvm" command, such as "nvvm", "nvmm"
2. Observe that the suggestion recommends the command "nvm." 
   (Currently, only 'nm' is recommended, but I want to make 'nvm' come out as well.)

The output of The Fuck with THEFUCK_DEBUG=true exported (typically execute export THEFUCK_DEBUG=true in your shell before The Fuck) :

N/A

If the bug only appears with a specific application, the output of that application and its version :

N/A

Anything else you think is relevant :

N/A

Additional Information:

I attempted to add a rule to correct the typo in the "nvm" command by creating a new rule file nvm.py in the rule directory. Here are the three attempts:

import re

def match(command):
    return (
        "not found" in command.output
        and any(re.search(r"\bnvm\b", arg) for arg in command.script_parts)
    )

def get_new_command(command):
    return "nvm " + " ".join(command.script_parts[1:])
from difflib import SequenceMatcher

def match(command):
    if SequenceMatcher(None, command.script_parts[0], "nvm").ratio() > 0.6:
        return 1
    else:
        return 0

def get_new_command(command):
    return "nvm"
from thefuck.utils import for_app, get_closest

@for_app('nvm')
def match(command):
    return 'command not found' in command.stderr

def get_new_command(command):
    closest_match = get_closest(command.script, ['nvm'], cutoff=0.8)

    if closest_match:
        new_command = command.script.replace(closest_match, 'nvm')
        return new_command

    return ['nvm']

However, none of these rules seem to be recognized by The Fuck. I would appreciate any guidance or suggestions on how to correctly implement the rule for correcting the typo in the "nvm" command. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant