Add rule to remove leading shell prompt literal $ (#996)
* Add rule to remove shell prompt literals $ Rule added to handle cases where the $ symbol is used in the command, this usually happens when the command is copy pasted from a documentation that includes the shell prompt symbol in the code blocks. * Change files using black and flake8 style check * Refactor tests and rule - Refactor test for cleaner test tables - Removed unnecessary requires_output=True option
This commit is contained in:
committed by
Vladimir Iakovlev
parent
d85099b8da
commit
793510ad48
@@ -0,0 +1,22 @@
|
||||
"""Fixes error for commands containing the shell prompt symbol '$'.
|
||||
|
||||
This usually happens when commands are copied from documentations
|
||||
including them in their code blocks.
|
||||
|
||||
Example:
|
||||
> $ git clone https://github.com/nvbn/thefuck.git
|
||||
bash: $: command not found...
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
|
||||
def match(command):
|
||||
return (
|
||||
"$: command not found" in command.output
|
||||
and re.search(r"^[\s]*\$ [\S]+", command.script) is not None
|
||||
)
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return command.script.replace("$", "", 1).strip()
|
||||
Reference in New Issue
Block a user