mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 07:04:12 +00:00 
			
		
		
		
	Add shells.quote
This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| import shlex | import shlex | ||||||
| from thefuck.utils import quote, for_app | from thefuck.shells import quote | ||||||
|  | from thefuck.utils import for_app | ||||||
|  |  | ||||||
|  |  | ||||||
| @for_app('sed') | @for_app('sed') | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ from time import time | |||||||
| import io | import io | ||||||
| import os | import os | ||||||
| import shlex | import shlex | ||||||
|  | import six | ||||||
| from .utils import DEVNULL, memoize, cache | from .utils import DEVNULL, memoize, cache | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -80,6 +81,16 @@ class Generic(object): | |||||||
|         """Split the command using shell-like syntax.""" |         """Split the command using shell-like syntax.""" | ||||||
|         return shlex.split(command) |         return shlex.split(command) | ||||||
|  |  | ||||||
|  |     def quote(self, s): | ||||||
|  |         """Return a shell-escaped version of the string s.""" | ||||||
|  |  | ||||||
|  |         if six.PY2: | ||||||
|  |             from pipes import quote | ||||||
|  |         else: | ||||||
|  |             from shlex import quote | ||||||
|  |  | ||||||
|  |         return quote(s) | ||||||
|  |  | ||||||
|  |  | ||||||
| class Bash(Generic): | class Bash(Generic): | ||||||
|     def app_alias(self, fuck): |     def app_alias(self, fuck): | ||||||
| @@ -294,6 +305,10 @@ def split_command(command): | |||||||
|     return _get_shell().split_command(command) |     return _get_shell().split_command(command) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def quote(s): | ||||||
|  |     return _get_shell().quote(s) | ||||||
|  |  | ||||||
|  |  | ||||||
| @memoize | @memoize | ||||||
| def get_history(): | def get_history(): | ||||||
|     return list(_get_shell().get_history()) |     return list(_get_shell().get_history()) | ||||||
|   | |||||||
| @@ -1,8 +1,7 @@ | |||||||
| import re | import re | ||||||
| from shlex import split |  | ||||||
| from decorator import decorator | from decorator import decorator | ||||||
| from ..types import Command | from ..utils import is_app | ||||||
| from ..utils import quote, is_app | from ..shells import quote, split_command | ||||||
|  |  | ||||||
|  |  | ||||||
| @decorator | @decorator | ||||||
| @@ -24,7 +23,7 @@ def git_support(fn, command): | |||||||
|         #     'commit' '--amend' |         #     'commit' '--amend' | ||||||
|         # which is surprising and does not allow to easily test for |         # which is surprising and does not allow to easily test for | ||||||
|         # eg. 'git commit' |         # eg. 'git commit' | ||||||
|         expansion = ' '.join(map(quote, split(search.group(2)))) |         expansion = ' '.join(map(quote, split_command(search.group(2)))) | ||||||
|         new_script = command.script.replace(alias, expansion) |         new_script = command.script.replace(alias, expansion) | ||||||
|  |  | ||||||
|         command = command.update(script=new_script) |         command = command.update(script=new_script) | ||||||
|   | |||||||
| @@ -12,16 +12,10 @@ from inspect import getargspec | |||||||
|  |  | ||||||
| from pathlib import Path | from pathlib import Path | ||||||
| import pkg_resources | import pkg_resources | ||||||
| import six |  | ||||||
| from .conf import settings | from .conf import settings | ||||||
|  |  | ||||||
| DEVNULL = open(os.devnull, 'w') | DEVNULL = open(os.devnull, 'w') | ||||||
|  |  | ||||||
| if six.PY2: |  | ||||||
|     from pipes import quote |  | ||||||
| else: |  | ||||||
|     from shlex import quote |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def memoize(fn): | def memoize(fn): | ||||||
|     """Caches previous calls to the function.""" |     """Caches previous calls to the function.""" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user