mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 07:04:12 +00:00 
			
		
		
		
	#78 Disable when can't import CommandNotFound
				
					
				
			This commit is contained in:
		| @@ -1,28 +1,23 @@ | |||||||
| import sys | try: | ||||||
|  |     import CommandNotFound | ||||||
|  | except ImportError: | ||||||
|  |     enabled_by_default = False | ||||||
|  |  | ||||||
|  |  | ||||||
| def match(command, settings): | def match(command, settings): | ||||||
|     try: |     if 'not found' in command.stderr: | ||||||
|         import CommandNotFound |         try: | ||||||
|         if 'not found' in command.stderr: |             c = CommandNotFound.CommandNotFound() | ||||||
|             try: |             pkgs = c.getPackages(command.script.split(" ")[0]) | ||||||
|                 c = CommandNotFound.CommandNotFound() |             name, _ = pkgs[0] | ||||||
|                 pkgs = c.getPackages(command.script.split(" ")[0]) |             return True | ||||||
|                 name,_ = pkgs[0] |         except IndexError: | ||||||
|                 return True |             # IndexError is thrown when no matching package is found | ||||||
|             except IndexError: |             return False | ||||||
|                 # IndexError is thrown when no matching package is found |  | ||||||
|                 return False |  | ||||||
|     except: |  | ||||||
|         return False |  | ||||||
|  |  | ||||||
| def get_new_command(command, settings): | def get_new_command(command, settings): | ||||||
|     try: |     c = CommandNotFound.CommandNotFound() | ||||||
|         import CommandNotFound |     pkgs = c.getPackages(command.script.split(" ")[0]) | ||||||
|         c = CommandNotFound.CommandNotFound() |     name, _ = pkgs[0] | ||||||
|         if 'not found' in command.stderr: |     return "sudo apt-get install {} && {}".format(name, command.script) | ||||||
|             pkgs = c.getPackages(command.script.split(" ")[0]) |  | ||||||
|             name,_ = pkgs[0] |  | ||||||
|             return "sudo apt-get install %s" % name |  | ||||||
|     except: |  | ||||||
|         sys.stderr.write("Can't apt fuck\n") |  | ||||||
|         return "" |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user