From 4f87141f0c1b3c7848460fafa34b721dfe999d01 Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Wed, 23 Nov 2016 07:43:25 -0500 Subject: [PATCH] bash: fallback to generic parser if bashlex fails --- thefuck/shells/bash.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/thefuck/shells/bash.py b/thefuck/shells/bash.py index 0ab3271..1d8ab7d 100644 --- a/thefuck/shells/bash.py +++ b/thefuck/shells/bash.py @@ -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