mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-29 22:24:44 +00:00 
			
		
		
		
	Support aliases with equal sign (#808)
* #N/A: Remove `pip` from requirements.txt * #807: Expect aliases declared with equal sign too This fixes #807
This commit is contained in:
		
				
					committed by
					
						 Vladimir Iakovlev
						Vladimir Iakovlev
					
				
			
			
				
	
			
			
			
						parent
						
							68949a5922
						
					
				
				
					commit
					8db3cf6048
				
			| @@ -16,7 +16,8 @@ class TestFish(object): | ||||
|         mock.return_value.stdout.read.side_effect = [( | ||||
|             b'cd\nfish_config\nfuck\nfunced\nfuncsave\ngrep\nhistory\nll\nls\n' | ||||
|             b'man\nmath\npopd\npushd\nruby'), | ||||
|             b'alias fish_key_reader /usr/bin/fish_key_reader\nalias g git'] | ||||
|             (b'alias fish_key_reader /usr/bin/fish_key_reader\nalias g git\n' | ||||
|              b'alias alias_with_equal_sign=echo\ninvalid_alias'), b'func1\nfunc2', b''] | ||||
|         return mock | ||||
|  | ||||
|     @pytest.mark.parametrize('key, value', [ | ||||
| @@ -69,7 +70,9 @@ class TestFish(object): | ||||
|                                        'pushd': 'pushd', | ||||
|                                        'ruby': 'ruby', | ||||
|                                        'g': 'git', | ||||
|                                        'fish_key_reader': '/usr/bin/fish_key_reader'} | ||||
|                                        'fish_key_reader': '/usr/bin/fish_key_reader', | ||||
|                                        'alias_with_equal_sign': 'echo'} | ||||
|         assert shell.get_aliases() == {'func1': 'func1', 'func2': 'func2'} | ||||
|  | ||||
|     def test_app_alias(self, shell): | ||||
|         assert 'function fuck' in shell.app_alias('fuck') | ||||
|   | ||||
| @@ -20,9 +20,17 @@ def _get_functions(overridden): | ||||
| def _get_aliases(overridden): | ||||
|     aliases = {} | ||||
|     proc = Popen(['fish', '-ic', 'alias'], stdout=PIPE, stderr=DEVNULL) | ||||
|     alias_out = proc.stdout.read().decode('utf-8').strip().split('\n') | ||||
|     for alias in alias_out: | ||||
|         name, value = alias.replace('alias ', '', 1).split(' ', 1) | ||||
|     alias_out = proc.stdout.read().decode('utf-8').strip() | ||||
|     if not alias_out: | ||||
|         return aliases | ||||
|     for alias in alias_out.split('\n'): | ||||
|         for separator in (' ', '='): | ||||
|             split_alias = alias.replace('alias ', '', 1).split(separator, 1) | ||||
|             if len(split_alias) == 2: | ||||
|                 name, value = split_alias | ||||
|                 break | ||||
|         else: | ||||
|             continue | ||||
|         if name not in overridden: | ||||
|             aliases[name] = value | ||||
|     return aliases | ||||
|   | ||||
		Reference in New Issue
	
	Block a user