mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	#N/A: Add slow_commands and wait_slow_command settings options
				
					
				
			This commit is contained in:
		
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								README.md
									
									
									
									
									
								
							| @@ -303,7 +303,9 @@ The Fuck has a few settings parameters which can be changed in `$XDG_CONFIG_HOME | |||||||
| * `priority` – dict with rules priorities, rule with lower `priority` will be matched first; | * `priority` – dict with rules priorities, rule with lower `priority` will be matched first; | ||||||
| * `debug` – enables debug output, by default `False`; | * `debug` – enables debug output, by default `False`; | ||||||
| * `history_limit` – numeric value of how many history commands will be scanned, like `2000`; | * `history_limit` – numeric value of how many history commands will be scanned, like `2000`; | ||||||
| * `alter_history` – push fixed command to history, by default `True`. | * `alter_history` – push fixed command to history, by default `True`; | ||||||
|  | * `wait_slow_command` – max amount of time in seconds for getting previous command output if it in `slow_commands` list; | ||||||
|  | * `slow_commands` – list of slow commands. | ||||||
|  |  | ||||||
| Example of `settings.py`: | Example of `settings.py`: | ||||||
|  |  | ||||||
| @@ -315,6 +317,9 @@ wait_command = 10 | |||||||
| no_colors = False | no_colors = False | ||||||
| priority = {'sudo': 100, 'no_command': 9999} | priority = {'sudo': 100, 'no_command': 9999} | ||||||
| debug = False | debug = False | ||||||
|  | history_limit = 9999 | ||||||
|  | wait_slow_command = 20 | ||||||
|  | slow_commands = ['react-native', 'gradle'] | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| Or via environment variables: | Or via environment variables: | ||||||
| @@ -328,7 +333,9 @@ Or via environment variables: | |||||||
| rule with lower `priority` will be matched first; | rule with lower `priority` will be matched first; | ||||||
| * `THEFUCK_DEBUG` – enables debug output, `true/false`; | * `THEFUCK_DEBUG` – enables debug output, `true/false`; | ||||||
| * `THEFUCK_HISTORY_LIMIT` – how many history commands will be scanned, like `2000`; | * `THEFUCK_HISTORY_LIMIT` – how many history commands will be scanned, like `2000`; | ||||||
| * `THEFUCK_ALTER_HISTORY` – push fixed command to history `true/false`. | * `THEFUCK_ALTER_HISTORY` – push fixed command to history `true/false`; | ||||||
|  | * `THEFUCK_WAIT_SLOW_COMMAND` – max amount of time in seconds for getting previous command output if it in `slow_commands` list; | ||||||
|  | * `THEFUCK_SLOW_COMMANDS` – list of slow commands, like `lein:gradle`. | ||||||
|  |  | ||||||
| For example: | For example: | ||||||
|  |  | ||||||
|   | |||||||
| @@ -59,7 +59,9 @@ class TestSettingsFromEnv(object): | |||||||
|                         'THEFUCK_WAIT_COMMAND': '55', |                         'THEFUCK_WAIT_COMMAND': '55', | ||||||
|                         'THEFUCK_REQUIRE_CONFIRMATION': 'true', |                         'THEFUCK_REQUIRE_CONFIRMATION': 'true', | ||||||
|                         'THEFUCK_NO_COLORS': 'false', |                         'THEFUCK_NO_COLORS': 'false', | ||||||
|                         'THEFUCK_PRIORITY': 'bash=10:lisp=wrong:vim=15'}) |                         'THEFUCK_PRIORITY': 'bash=10:lisp=wrong:vim=15', | ||||||
|  |                         'THEFUCK_WAIT_SLOW_COMMAND': '999', | ||||||
|  |                         'THEFUCK_SLOW_COMMANDS': 'lein:react-native:./gradlew'}) | ||||||
|         settings.init() |         settings.init() | ||||||
|         assert settings.rules == ['bash', 'lisp'] |         assert settings.rules == ['bash', 'lisp'] | ||||||
|         assert settings.exclude_rules == ['git', 'vim'] |         assert settings.exclude_rules == ['git', 'vim'] | ||||||
| @@ -67,6 +69,8 @@ class TestSettingsFromEnv(object): | |||||||
|         assert settings.require_confirmation is True |         assert settings.require_confirmation is True | ||||||
|         assert settings.no_colors is False |         assert settings.no_colors is False | ||||||
|         assert settings.priority == {'bash': 10, 'vim': 15} |         assert settings.priority == {'bash': 10, 'vim': 15} | ||||||
|  |         assert settings.wait_slow_command == 999 | ||||||
|  |         assert settings.slow_commands == ['lein', 'react-native', './gradlew'] | ||||||
|  |  | ||||||
|     def test_from_env_with_DEFAULT(self, environ, settings): |     def test_from_env_with_DEFAULT(self, environ, settings): | ||||||
|         environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'}) |         environ.update({'THEFUCK_RULES': 'DEFAULT_RULES:bash:lisp'}) | ||||||
|   | |||||||
| @@ -92,13 +92,13 @@ class Settings(dict): | |||||||
|             return self._rules_from_env(val) |             return self._rules_from_env(val) | ||||||
|         elif attr == 'priority': |         elif attr == 'priority': | ||||||
|             return dict(self._priority_from_env(val)) |             return dict(self._priority_from_env(val)) | ||||||
|         elif attr == 'wait_command': |         elif attr in ('wait_command', 'history_limit', 'wait_slow_command'): | ||||||
|             return int(val) |             return int(val) | ||||||
|         elif attr in ('require_confirmation', 'no_colors', 'debug', |         elif attr in ('require_confirmation', 'no_colors', 'debug', | ||||||
|                       'alter_history'): |                       'alter_history'): | ||||||
|             return val.lower() == 'true' |             return val.lower() == 'true' | ||||||
|         elif attr == 'history_limit': |         elif attr == 'slow_commands': | ||||||
|             return int(val) |             return val.split(':') | ||||||
|         else: |         else: | ||||||
|             return val |             return val | ||||||
|  |  | ||||||
|   | |||||||
| @@ -31,6 +31,8 @@ DEFAULT_SETTINGS = {'rules': DEFAULT_RULES, | |||||||
|                     'priority': {}, |                     'priority': {}, | ||||||
|                     'history_limit': None, |                     'history_limit': None, | ||||||
|                     'alter_history': True, |                     'alter_history': True, | ||||||
|  |                     'wait_slow_command': 15, | ||||||
|  |                     'slow_commands': ['lein'], | ||||||
|                     'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}} |                     'env': {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}} | ||||||
|  |  | ||||||
| ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', | ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', | ||||||
| @@ -41,7 +43,9 @@ ENV_TO_ATTR = {'THEFUCK_RULES': 'rules', | |||||||
|                'THEFUCK_DEBUG': 'debug', |                'THEFUCK_DEBUG': 'debug', | ||||||
|                'THEFUCK_PRIORITY': 'priority', |                'THEFUCK_PRIORITY': 'priority', | ||||||
|                'THEFUCK_HISTORY_LIMIT': 'history_limit', |                'THEFUCK_HISTORY_LIMIT': 'history_limit', | ||||||
|                'THEFUCK_ALTER_HISTORY': 'alter_history'} |                'THEFUCK_ALTER_HISTORY': 'alter_history', | ||||||
|  |                'THEFUCK_WAIT_SLOW_COMMAND': 'wait_slow_command', | ||||||
|  |                'THEFUCK_SLOW_COMMANDS': 'slow_commands'} | ||||||
|  |  | ||||||
| SETTINGS_HEADER = u"""# The Fuck settings file | SETTINGS_HEADER = u"""# The Fuck settings file | ||||||
| # | # | ||||||
|   | |||||||
| @@ -61,7 +61,7 @@ class Command(object): | |||||||
|         return Command(**kwargs) |         return Command(**kwargs) | ||||||
|  |  | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def _wait_output(popen): |     def _wait_output(popen, is_slow): | ||||||
|         """Returns `True` if we can get output of the command in the |         """Returns `True` if we can get output of the command in the | ||||||
|         `settings.wait_command` time. |         `settings.wait_command` time. | ||||||
|  |  | ||||||
| @@ -73,7 +73,8 @@ class Command(object): | |||||||
|         """ |         """ | ||||||
|         proc = Process(popen.pid) |         proc = Process(popen.pid) | ||||||
|         try: |         try: | ||||||
|             proc.wait(settings.wait_command) |             proc.wait(settings.wait_slow_command if is_slow | ||||||
|  |                       else settings.wait_command) | ||||||
|             return True |             return True | ||||||
|         except TimeoutExpired: |         except TimeoutExpired: | ||||||
|             for child in proc.children(recursive=True): |             for child in proc.children(recursive=True): | ||||||
| @@ -113,9 +114,12 @@ class Command(object): | |||||||
|         env = dict(os.environ) |         env = dict(os.environ) | ||||||
|         env.update(settings.env) |         env.update(settings.env) | ||||||
|  |  | ||||||
|         with logs.debug_time(u'Call: {}; with env: {};'.format(script, env)): |         is_slow = script.split(' ')[0] in settings.slow_commands | ||||||
|             result = Popen(script, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) |         with logs.debug_time(u'Call: {}; with env: {}; is slow: '.format( | ||||||
|             if cls._wait_output(result): |                 script, env, is_slow)): | ||||||
|  |             result = Popen(script, shell=True, stdin=PIPE, | ||||||
|  |                            stdout=PIPE, stderr=PIPE, env=env) | ||||||
|  |             if cls._wait_output(result, is_slow): | ||||||
|                 stdout = result.stdout.read().decode('utf-8') |                 stdout = result.stdout.read().decode('utf-8') | ||||||
|                 stderr = result.stderr.read().decode('utf-8') |                 stderr = result.stderr.read().decode('utf-8') | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user