@@ -55,7 +55,7 @@ def organize_commands(corrected_commands):
|
||||
key=lambda corrected_command: corrected_command.priority)
|
||||
|
||||
logs.debug('Corrected commands: '.format(
|
||||
', '.join(str(cmd) for cmd in [first_command] + sorted_commands)))
|
||||
', '.join(u'{}'.format(cmd) for cmd in [first_command] + sorted_commands)))
|
||||
|
||||
for command in sorted_commands:
|
||||
yield command
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Attempts to spellcheck and correct failed cd commands"""
|
||||
|
||||
import os
|
||||
import six
|
||||
from difflib import get_close_matches
|
||||
from thefuck.specific.sudo import sudo_support
|
||||
from thefuck.rules import cd_mkdir
|
||||
@@ -36,7 +37,10 @@ def get_new_command(command):
|
||||
dest = command.script_parts[1].split(os.sep)
|
||||
if dest[-1] == '':
|
||||
dest = dest[:-1]
|
||||
cwd = os.getcwd()
|
||||
if six.PY2:
|
||||
cwd = os.getcwdu()
|
||||
else:
|
||||
cwd = os.getcwd()
|
||||
for directory in dest:
|
||||
if directory == ".":
|
||||
continue
|
||||
@@ -48,7 +52,7 @@ def get_new_command(command):
|
||||
cwd = os.path.join(cwd, best_matches[0])
|
||||
else:
|
||||
return cd_mkdir.get_new_command(command)
|
||||
return 'cd "{0}"'.format(cwd)
|
||||
return u'cd "{0}"'.format(cwd)
|
||||
|
||||
|
||||
enabled_by_default = True
|
||||
|
||||
@@ -19,7 +19,7 @@ def _zip_file(command):
|
||||
if c.endswith('.zip'):
|
||||
return c
|
||||
else:
|
||||
return '{}.zip'.format(c)
|
||||
return u'{}.zip'.format(c)
|
||||
|
||||
|
||||
@for_app('unzip')
|
||||
@@ -29,7 +29,7 @@ def match(command):
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return '{} -d {}'.format(command.script, quote(_zip_file(command)[:-4]))
|
||||
return u'{} -d {}'.format(command.script, quote(_zip_file(command)[:-4]))
|
||||
|
||||
|
||||
def side_effect(old_cmd, command):
|
||||
|
||||
@@ -58,7 +58,7 @@ def match(command):
|
||||
return _search(command.stderr) or _search(command.stdout)
|
||||
|
||||
|
||||
@default_settings({'fixlinecmd': '{editor} {file} +{line}',
|
||||
@default_settings({'fixlinecmd': u'{editor} {file} +{line}',
|
||||
'fixcolcmd': None})
|
||||
def get_new_command(command):
|
||||
m = _search(command.stderr) or _search(command.stdout)
|
||||
|
||||
@@ -7,4 +7,4 @@ def match(command):
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return 'grep -r {}'.format(command.script[5:])
|
||||
return u'grep -r {}'.format(command.script[5:])
|
||||
|
||||
+7
-8
@@ -11,7 +11,6 @@ import io
|
||||
import os
|
||||
import shlex
|
||||
import six
|
||||
import sys
|
||||
from .utils import DEVNULL, memoize, cache
|
||||
|
||||
|
||||
@@ -51,10 +50,11 @@ class Generic(object):
|
||||
history_file_name = self._get_history_file_name()
|
||||
if os.path.isfile(history_file_name):
|
||||
with open(history_file_name, 'a') as history:
|
||||
if sys.version_info >= (3, 0):
|
||||
history.write(self._get_history_line(command_script))
|
||||
entry = self._get_history_line(command_script)
|
||||
if six.PY2:
|
||||
history.write(entry.encode('utf-8'))
|
||||
else:
|
||||
history.write(self._get_history_line(command_script).encode("utf-8"))
|
||||
history.write(entry)
|
||||
|
||||
def _script_from_history(self, line):
|
||||
"""Returns prepared history line.
|
||||
@@ -84,10 +84,9 @@ class Generic(object):
|
||||
|
||||
def split_command(self, command):
|
||||
"""Split the command using shell-like syntax."""
|
||||
if sys.version_info >= (3, 0):
|
||||
return shlex.split(command)
|
||||
else:
|
||||
return shlex.split(command.encode("utf-8"))
|
||||
if six.PY2:
|
||||
return [s.decode('utf8') for s in shlex.split(command.encode('utf8'))]
|
||||
return shlex.split(command)
|
||||
|
||||
def quote(self, s):
|
||||
"""Return a shell-escaped version of the string s."""
|
||||
|
||||
+2
-1
@@ -267,7 +267,7 @@ class CorrectedCommand(object):
|
||||
return (self.script, self.side_effect).__hash__()
|
||||
|
||||
def __repr__(self):
|
||||
return 'CorrectedCommand(script={}, side_effect={}, priority={})'.format(
|
||||
return u'CorrectedCommand(script={}, side_effect={}, priority={})'.format(
|
||||
self.script, self.side_effect, self.priority)
|
||||
|
||||
def run(self, old_cmd):
|
||||
@@ -279,4 +279,5 @@ class CorrectedCommand(object):
|
||||
if self.side_effect:
|
||||
compatibility_call(self.side_effect, old_cmd, self.script)
|
||||
shells.put_to_history(self.script)
|
||||
# This depends on correct setting of PYTHONIOENCODING by the alias:
|
||||
print(self.script)
|
||||
|
||||
Reference in New Issue
Block a user