Skip to content

Commit

Permalink
#1039: Remove all leading $ not just one
Browse files Browse the repository at this point in the history
  • Loading branch information
theslimshaney authored and scorphus committed Jun 30, 2021
1 parent 7f97818 commit 9201ce7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion tests/rules/test_remove_shell_prompt_literal.py
Expand Up @@ -8,7 +8,15 @@ def output():
return "$: command not found"


@pytest.mark.parametrize("script", ["$ cd newdir", " $ cd newdir"])
@pytest.mark.parametrize(
"script",
[
"$ cd newdir",
" $ cd newdir",
"$ $ cd newdir"
" $ $ cd newdir",
],
)
def test_match(script, output):
assert match(Command(script, output))

Expand All @@ -31,7 +39,9 @@ def test_not_match(command):
"script, new_command",
[
("$ cd newdir", "cd newdir"),
("$ $ cd newdir", "cd newdir"),
("$ python3 -m virtualenv env", "python3 -m virtualenv env"),
(" $ $ $ python3 -m virtualenv env", "python3 -m virtualenv env"),
],
)
def test_get_new_command(script, new_command, output):
Expand Down
5 changes: 3 additions & 2 deletions thefuck/rules/remove_shell_prompt_literal.py
@@ -1,4 +1,5 @@
"""Fixes error for commands containing the shell prompt symbol '$'.
"""Fixes error for commands containing one or more occurrences of the shell
prompt symbol '$'.
This usually happens when commands are copied from documentations
including them in their code blocks.
Expand All @@ -19,4 +20,4 @@ def match(command):


def get_new_command(command):
return command.script.replace("$", "", 1).strip()
return command.script.lstrip("$ ")

0 comments on commit 9201ce7

Please sign in to comment.