mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 07:04:12 +00:00 
			
		
		
		
	| @@ -156,6 +156,7 @@ using matched rule and run it. Rules enabled by default: | ||||
|  | ||||
| * `brew_unknown_command` – fixes wrong brew commands, for example `brew docto/brew doctor`; | ||||
| * `cd_parent` – changes `cd..` to `cd ..`; | ||||
| * `cd_mkdir` – creates directories before cd'ing into them; | ||||
| * `cp_omitting_directory` – adds `-a` when you `cp` directory; | ||||
| * `fix_alt_space` – replaces Alt+Space with Space character; | ||||
| * `git_no_command` – fixes wrong git commands like `git brnch`; | ||||
|   | ||||
							
								
								
									
										19
									
								
								tests/rules/test_cd_mkdir.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/rules/test_cd_mkdir.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| from mock import Mock | ||||
| from thefuck.rules.cd_mkdir import match, get_new_command | ||||
|  | ||||
|  | ||||
| def test_match(): | ||||
|     assert match(Mock(script='cd foo', stderr='cd: foo: No such file or directory'), | ||||
|                  None) | ||||
|     assert match(Mock(script='cd foo/bar/baz', stderr='cd: foo: No such file or directory'), | ||||
|                  None) | ||||
|     assert match(Mock(script='cd foo/bar/baz', stderr='cd: can\'t cd to foo/bar/baz'), | ||||
|                  None) | ||||
|     assert not match(Mock(script='cd foo', | ||||
|                           stderr=''), None) | ||||
|     assert not match(Mock(script='', stderr=''), None) | ||||
|  | ||||
|  | ||||
| def test_get_new_command(): | ||||
|     assert get_new_command(Mock(script='cd foo'), None) == 'mkdir -p foo && cd foo' | ||||
|     assert get_new_command(Mock(script='cd foo/bar/baz'), None) == 'mkdir -p foo/bar/baz && cd foo/bar/baz' | ||||
							
								
								
									
										14
									
								
								thefuck/rules/cd_mkdir.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								thefuck/rules/cd_mkdir.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| import re | ||||
| from thefuck.utils import sudo_support | ||||
|  | ||||
|  | ||||
| @sudo_support | ||||
| def match(command, settings): | ||||
|     return (command.script.startswith('cd ') | ||||
|         and ('no such file or directory' in command.stderr.lower() | ||||
|             or 'cd: can\'t cd to' in command.stderr.lower())) | ||||
|  | ||||
|  | ||||
| @sudo_support | ||||
| def get_new_command(command, settings): | ||||
|     return re.sub(r'^cd (.*)', 'mkdir -p \\1 && cd \\1', command.script) | ||||
		Reference in New Issue
	
	Block a user