1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 10:11:14 +00:00

#580: Use bashlex in generic shell

This commit is contained in:
Vladimir Iakovlev 2017-01-09 17:50:23 +01:00
parent d1b9492085
commit a6f63c0568
2 changed files with 14 additions and 13 deletions

View File

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

View File

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