1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-20 20:09:07 +00:00

Add shells.quote

This commit is contained in:
mcarton 2015-10-28 14:16:01 +01:00
parent dae58211ba
commit ecfc180280
4 changed files with 20 additions and 11 deletions

View File

@ -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')

View File

@ -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())

View File

@ -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)

View File

@ -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."""