Merge pull request #580 from josephfrazier/bash-command-substitution
bash: fix parsing of command substitution
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import bashlex
|
||||
from ..conf import settings
|
||||
from ..utils import memoize
|
||||
from .generic import Generic
|
||||
@@ -45,3 +46,13 @@ 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)
|
||||
|
||||
@@ -65,9 +65,17 @@ class Generic(object):
|
||||
|
||||
def split_command(self, command):
|
||||
"""Split the command using shell-like syntax."""
|
||||
return self.decode_utf8(shlex.split(self.encode_utf8(command)))
|
||||
|
||||
def encode_utf8(self, command):
|
||||
if six.PY2:
|
||||
return [s.decode('utf8') for s in shlex.split(command.encode('utf8'))]
|
||||
return shlex.split(command)
|
||||
return command.encode('utf8')
|
||||
return command
|
||||
|
||||
def decode_utf8(self, command_parts):
|
||||
if six.PY2:
|
||||
return [s.decode('utf8') for s in command_parts]
|
||||
return command_parts
|
||||
|
||||
def quote(self, s):
|
||||
"""Return a shell-escaped version of the string s."""
|
||||
|
||||
Reference in New Issue
Block a user