diff --git a/thefuck/shells/bash.py b/thefuck/shells/bash.py index f914163f..d6f4cdff 100644 --- a/thefuck/shells/bash.py +++ b/thefuck/shells/bash.py @@ -1,5 +1,4 @@ import os -import bashlex from ..conf import settings from ..utils import memoize from .generic import Generic @@ -46,13 +45,3 @@ class Bash(Generic): else: config = 'bash config' return 'eval $(thefuck --alias)', config - - def split_command(self, command): - generic = Generic() - - # If bashlex fails for some reason, fallback to shlex - # See https://github.com/idank/bashlex#limitations - try: - return generic.decode_utf8(list(bashlex.split(generic.encode_utf8(command)))) - except: - return generic.split_command(command) diff --git a/thefuck/shells/generic.py b/thefuck/shells/generic.py index ec38df1c..9aa65b3b 100644 --- a/thefuck/shells/generic.py +++ b/thefuck/shells/generic.py @@ -1,6 +1,7 @@ import io import os import shlex +import bashlex import six from ..utils import memoize from ..conf import settings @@ -64,8 +65,19 @@ class Generic(object): return def split_command(self, command): - """Split the command using shell-like syntax.""" - return self.decode_utf8(shlex.split(self.encode_utf8(command))) + """Split the command using shell-like syntax. + + If bashlex fails for some reason, fallback to shlex + See https://github.com/idank/bashlex#limitations + """ + encoded = self.encode_utf8(command) + + try: + splitted = list(bashlex.split(encoded)) + except Exception: + splitted = shlex.split(encoded) + + return self.decode_utf8(splitted) def encode_utf8(self, command): if six.PY2: