mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 09:39:01 +00:00
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.
This commit is contained in:
parent
70b414aca2
commit
d7e2d4e3c6
@ -279,6 +279,7 @@ following rules are enabled by default:
|
|||||||
* `quotation_marks` – fixes uneven usage of `'` and `"` when containing args';
|
* `quotation_marks` – fixes uneven usage of `'` and `"` when containing args';
|
||||||
* `path_from_history` – replaces not found path with similar absolute path from history;
|
* `path_from_history` – replaces not found path with similar absolute path from history;
|
||||||
* `react_native_command_unrecognized` – fixes unrecognized `react-native` commands;
|
* `react_native_command_unrecognized` – fixes unrecognized `react-native` commands;
|
||||||
|
* `remove_shell_prompt_literal` – remove leading shell prompt symbol `$`, common when copying commands from documentations;
|
||||||
* `remove_trailing_cedilla` – remove trailling cedillas `ç`, a common typo for european keyboard layouts;
|
* `remove_trailing_cedilla` – remove trailling cedillas `ç`, a common typo for european keyboard layouts;
|
||||||
* `rm_dir` – adds `-rf` when you try to remove a directory;
|
* `rm_dir` – adds `-rf` when you try to remove a directory;
|
||||||
* `scm_correction` – corrects wrong scm like `hg log` to `git log`;
|
* `scm_correction` – corrects wrong scm like `hg log` to `git log`;
|
||||||
|
32
tests/rules/test_remove_shell_prompt_literal.py
Normal file
32
tests/rules/test_remove_shell_prompt_literal.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
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'),
|
||||||
|
])
|
||||||
|
def test_match(command):
|
||||||
|
assert match(command)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command',
|
||||||
|
[
|
||||||
|
Command('$', ''),
|
||||||
|
Command('$?', ''),
|
||||||
|
Command(' $?', ''),
|
||||||
|
Command('', ''),
|
||||||
|
])
|
||||||
|
def test_not_match(command):
|
||||||
|
assert not match(command)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command, new_command',
|
||||||
|
[
|
||||||
|
(Command('$ cd newdir', ''), 'cd newdir'),
|
||||||
|
(Command('$ python3 -m virtualenv env', ''), 'python3 -m virtualenv env'),
|
||||||
|
])
|
||||||
|
def test_get_new_command(command, new_command):
|
||||||
|
assert get_new_command(command) == new_command
|
20
thefuck/rules/remove_shell_prompt_literal.py
Normal file
20
thefuck/rules/remove_shell_prompt_literal.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"""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
|
Loading…
x
Reference in New Issue
Block a user