mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	Merge pull request #171 from mcarton/dry
Add a don't repeat yourself rule
This commit is contained in:
		| @@ -144,6 +144,7 @@ using matched rule and run it. Rules enabled by default: | |||||||
| * `cd_parent` – changes `cd..` to `cd ..`; | * `cd_parent` – changes `cd..` to `cd ..`; | ||||||
| * `cd_mkdir` – creates directories before cd'ing into them; | * `cd_mkdir` – creates directories before cd'ing into them; | ||||||
| * `cp_omitting_directory` – adds `-a` when you `cp` directory; | * `cp_omitting_directory` – adds `-a` when you `cp` directory; | ||||||
|  | * `dry` – fix repetitions like "git git push"; | ||||||
| * `fix_alt_space` – replaces Alt+Space with Space character; | * `fix_alt_space` – replaces Alt+Space with Space character; | ||||||
| * `git_add` – fix *"Did you forget to 'git add'?"*; | * `git_add` – fix *"Did you forget to 'git add'?"*; | ||||||
| * `git_checkout` – creates the branch before checking-out; | * `git_checkout` – creates the branch before checking-out; | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								tests/rules/test_dry.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								tests/rules/test_dry.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | import pytest | ||||||
|  | from thefuck.rules.dry import match, get_new_command | ||||||
|  | from tests.utils import Command | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @pytest.mark.parametrize('command', [ | ||||||
|  |     Command(script='cd cd foo'), | ||||||
|  |     Command(script='git git push origin/master')]) | ||||||
|  | def test_match(command): | ||||||
|  |     assert match(command, None) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @pytest.mark.parametrize('command, new_command', [ | ||||||
|  |     (Command('cd cd foo'), 'cd foo'), | ||||||
|  |     (Command('git git push origin/master'), 'git push origin/master')]) | ||||||
|  | def test_get_new_command(command, new_command): | ||||||
|  |     assert get_new_command(command, None) == new_command | ||||||
							
								
								
									
										12
									
								
								thefuck/rules/dry.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								thefuck/rules/dry.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | def match(command, settings): | ||||||
|  |     split_command = command.script.split() | ||||||
|  |  | ||||||
|  |     return len(split_command) >= 2 and split_command[0] == split_command[1] | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def get_new_command(command, settings): | ||||||
|  |     return command.script[command.script.find(' ')+1:] | ||||||
|  |  | ||||||
|  | # it should be rare enough to actually have to type twice the same word, so | ||||||
|  | # this rule can have a higher priority to come before things like "cd cd foo" | ||||||
|  | priority = 900 | ||||||
		Reference in New Issue
	
	Block a user