From ecfc1802804f4e705c92499784251cbe727ffc23 Mon Sep 17 00:00:00 2001 From: mcarton Date: Wed, 28 Oct 2015 14:16:01 +0100 Subject: [PATCH] Add shells.quote --- thefuck/rules/sed_unterminated_s.py | 3 ++- thefuck/shells.py | 15 +++++++++++++++ thefuck/specific/git.py | 7 +++---- thefuck/utils.py | 6 ------ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/thefuck/rules/sed_unterminated_s.py b/thefuck/rules/sed_unterminated_s.py index 718d6940..1fb6233d 100644 --- a/thefuck/rules/sed_unterminated_s.py +++ b/thefuck/rules/sed_unterminated_s.py @@ -1,5 +1,6 @@ import shlex -from thefuck.utils import quote, for_app +from thefuck.shells import quote +from thefuck.utils import for_app @for_app('sed') diff --git a/thefuck/shells.py b/thefuck/shells.py index cdded259..da5f95cb 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -10,6 +10,7 @@ from time import time import io import os import shlex +import six from .utils import DEVNULL, memoize, cache @@ -80,6 +81,16 @@ class Generic(object): """Split the command using shell-like syntax.""" 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): def app_alias(self, fuck): @@ -294,6 +305,10 @@ def split_command(command): return _get_shell().split_command(command) +def quote(s): + return _get_shell().quote(s) + + @memoize def get_history(): return list(_get_shell().get_history()) diff --git a/thefuck/specific/git.py b/thefuck/specific/git.py index 51a81ef4..a3654cc3 100644 --- a/thefuck/specific/git.py +++ b/thefuck/specific/git.py @@ -1,8 +1,7 @@ import re -from shlex import split from decorator import decorator -from ..types import Command -from ..utils import quote, is_app +from ..utils import is_app +from ..shells import quote, split_command @decorator @@ -24,7 +23,7 @@ def git_support(fn, command): # 'commit' '--amend' # which is surprising and does not allow to easily test for # 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) command = command.update(script=new_script) diff --git a/thefuck/utils.py b/thefuck/utils.py index c9c4e04a..ac011ec7 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -12,16 +12,10 @@ from inspect import getargspec from pathlib import Path import pkg_resources -import six from .conf import settings DEVNULL = open(os.devnull, 'w') -if six.PY2: - from pipes import quote -else: - from shlex import quote - def memoize(fn): """Caches previous calls to the function."""