mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 07:04:12 +00:00 
			
		
		
		
	Merge pull request #474 from scorphus/alias-variables
#301: Set variables within the alias
This commit is contained in:
		| @@ -46,6 +46,13 @@ class TestBash(object): | ||||
|         assert 'TF_ALIAS=fuck' in shell.app_alias('fuck') | ||||
|         assert 'PYTHONIOENCODING=utf-8' in shell.app_alias('fuck') | ||||
|  | ||||
|     def test_app_alias_variables_correctly_set(self, shell): | ||||
|         alias = shell.app_alias('fuck') | ||||
|         assert "alias fuck='TF_CMD=$(TF_ALIAS" in alias | ||||
|         assert '$(TF_ALIAS=fuck PYTHONIOENCODING' in alias | ||||
|         assert 'PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES' in alias | ||||
|         assert 'ALIASES=$(alias) thefuck' in alias | ||||
|  | ||||
|     def test_get_history(self, history_lines, shell): | ||||
|         history_lines(['ls', 'rm']) | ||||
|         assert list(shell.get_history()) == ['ls', 'rm'] | ||||
|   | ||||
| @@ -45,6 +45,13 @@ class TestZsh(object): | ||||
|         assert 'thefuck' in shell.app_alias('fuck') | ||||
|         assert 'PYTHONIOENCODING' in shell.app_alias('fuck') | ||||
|  | ||||
|     def test_app_alias_variables_correctly_set(self, shell): | ||||
|         alias = shell.app_alias('fuck') | ||||
|         assert "alias fuck='TF_CMD=$(TF_ALIAS" in alias | ||||
|         assert '$(TF_ALIAS=fuck PYTHONIOENCODING' in alias | ||||
|         assert 'PYTHONIOENCODING=utf-8 TF_SHELL_ALIASES' in alias | ||||
|         assert 'ALIASES=$(alias) thefuck' in alias | ||||
|  | ||||
|     def test_get_history(self, history_lines, shell): | ||||
|         history_lines([': 1432613911:0;ls', ': 1432613916:0;rm']) | ||||
|         assert list(shell.get_history()) == ['ls', 'rm'] | ||||
|   | ||||
| @@ -6,9 +6,11 @@ from .generic import Generic | ||||
|  | ||||
| class Bash(Generic): | ||||
|     def app_alias(self, fuck): | ||||
|         alias = "TF_ALIAS={0}" \ | ||||
|                 " alias {0}='PYTHONIOENCODING=utf-8" \ | ||||
|                 " TF_CMD=$(TF_SHELL_ALIASES=$(alias) thefuck $(fc -ln -1)) && " \ | ||||
|         # It is VERY important to have the variables declared WITHIN the alias | ||||
|         alias = "alias {0}='TF_CMD=$(TF_ALIAS={0}" \ | ||||
|                 " PYTHONIOENCODING=utf-8" \ | ||||
|                 " TF_SHELL_ALIASES=$(alias)" \ | ||||
|                 " thefuck $(fc -ln -1)) &&" \ | ||||
|                 " eval $TF_CMD".format(fuck) | ||||
|  | ||||
|         if settings.alter_history: | ||||
|   | ||||
| @@ -14,6 +14,7 @@ class Fish(Generic): | ||||
|             return ['cd', 'grep', 'ls', 'man', 'open'] | ||||
|  | ||||
|     def app_alias(self, fuck): | ||||
|         # It is VERY important to have the variables declared WITHIN the alias | ||||
|         return ('function {0} -d "Correct your previous console command"\n' | ||||
|                 '  set -l fucked_up_command $history[1]\n' | ||||
|                 '  env TF_ALIAS={0} PYTHONIOENCODING=utf-8' | ||||
|   | ||||
| @@ -7,10 +7,11 @@ from .generic import Generic | ||||
|  | ||||
| class Zsh(Generic): | ||||
|     def app_alias(self, alias_name): | ||||
|         alias = "alias {0}='TF_ALIAS={0}" \ | ||||
|         # It is VERY important to have the variables declared WITHIN the alias | ||||
|         alias = "alias {0}='TF_CMD=$(TF_ALIAS={0}" \ | ||||
|                 " PYTHONIOENCODING=utf-8" \ | ||||
|                 ' TF_SHELL_ALIASES=$(alias)' \ | ||||
|                 " TF_CMD=$(thefuck $(fc -ln -1 | tail -n 1)) &&" \ | ||||
|                 " TF_SHELL_ALIASES=$(alias)" \ | ||||
|                 " thefuck $(fc -ln -1 | tail -n 1)) &&" \ | ||||
|                 " eval $TF_CMD".format(alias_name) | ||||
|  | ||||
|         if settings.alter_history: | ||||
|   | ||||
| @@ -282,5 +282,5 @@ class CorrectedCommand(object): | ||||
|             compatibility_call(self.side_effect, old_cmd, self.script) | ||||
|         # This depends on correct setting of PYTHONIOENCODING by the alias: | ||||
|         logs.debug(u'PYTHONIOENCODING: {}'.format( | ||||
|             os.environ.get('PYTHONIOENCODING', '>-not-set-<'))) | ||||
|             os.environ.get('PYTHONIOENCODING', '!!not-set!!'))) | ||||
|         print(self.script) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user