-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add rule to remove leading shell prompt literal $ #996
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||
| import pytest | ||||||
| from thefuck.rules.remove_shell_prompt_literal import match, get_new_command | ||||||
| from thefuck.types import Command | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.parametrize( | ||||||
| "command", | ||||||
| [ | ||||||
| Command("$ cd newdir", "$: command not found"), | ||||||
|
||||||
| Command("$ cd newdir", "$: command not found"), | |
| "$ cd newdir", |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def test_match(command): | |
| def test_match(script): |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| assert match(command) | |
| assert match(Command(script, "$: command not found")) |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """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() | ||
|
|
||
|
|
||
| requires_output = True | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about parametrizing only
script(as string) and declare aCommandinstance with"$: command not found"asoutput?That would make all test tables more readable.