1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-22 12:58:33 +00:00

bash: fallback to generic parser if bashlex fails

This commit is contained in:
Joseph Frazier 2016-11-23 07:43:25 -05:00
parent dbedcc7aa6
commit 4f87141f0c

View File

@ -1,5 +1,6 @@
import os
import bashlex
import six
from ..conf import settings
from ..utils import memoize
from .generic import Generic
@ -48,4 +49,17 @@ class Bash(Generic):
return 'eval $(thefuck --alias)', config
def split_command(self, command):
return list(bashlex.split(command))
if six.PY2:
command = command.encode('utf8')
# If bashlex fails for some reason, fallback to shlex
# See https://github.com/idank/bashlex#limitations
try:
command_parts = list(bashlex.split(command))
except:
return Generic().split_command(command)
if six.PY2:
return [s.decode('utf8') for s in command_parts]
else:
return command_parts