free 명령어 인자를 수정하지 못하는 코드 보완

less than 1 minute read

free 명령어 인자를 수정하지 못하는 코드 보완

00

free는 시스템 메모리의 사용량을 알려주는 좋은 명령어입니다.

메모리의 상황을 모니터링할 때 자주 쓰는 명령어인데

fuck tool은 free의 인자를 제대로 추천하지

못하는 것을 발견하여 코드 보완을 했습니다.

기존 fuck tool은 free 명령어를 입력하면

1

2

위와 같이 명령어를 인식하지 못하거나

이상한 인자를 추천하고 있습니다.

인자가 하나인 경우

from difflib import SequenceMatcher

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

def get_new_command(command):
    new_cmds = ["free"]
    return [' '.join([new_command] + ["-h"])
            for new_command in new_cmds] 

commamd가 오타가 난 경우와

인자가 이상한 경우 두 경우를 고려해야합니다.

따라서 유사도가 60프로 이상일 때 풀에 넣고

코드 별로 -h, -b 같은 옵션을 join합니다.

인자가 두 개인 경우

from difflib import SequenceMatcher

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

def get_new_command(command):
    new_cmds = ["free"]
    return [' '.join([new_command] + ["-s"] + command.script_parts[2:])
            for new_command in new_cmds] 

인자를 두 개까지 받아야하기 때문에 -s -c 같은 옵션과

뒤에 따라오는 인자를 연이어 받아줍니다.

기여 결과

3

4

5

코드 기여 후 free의 인자를 알맞게 받고 있고

free와 인자 둘다 오타가 난 경우에도

무리없이 수정되는 것을 볼 수 있습니다.

옵션별 파일이 많은 관계로

커밋링크는 commit게시판을 참조합니다.

commit_link

Categories:

Updated: