1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-20 09:39:01 +00:00

getting closer...

This commit is contained in:
Jared Henry Oviatt 2015-05-11 02:39:05 -07:00
parent cf53571c83
commit c6ae4594a2
2 changed files with 13 additions and 11 deletions

View File

@ -91,9 +91,9 @@ class TestGetCommand(object):
(['thefuck', 'ls'], 'ls')]) (['thefuck', 'ls'], 'ls')])
def test_get_command_script(self, args, result): def test_get_command_script(self, args, result):
if result: if result:
assert main.get_command(Mock(), args).script == result assert main.get_command(Mock()).script == result
else: else:
assert main.get_command(Mock(), args) is None assert main.get_command(Mock()) is None
class TestGetMatchedRule(object): class TestGetMatchedRule(object):

View File

@ -1,14 +1,13 @@
from imp import load_source from imp import load_source
from pathlib import Path from pathlib import Path
from os.path import expanduser from os.path import expanduser
from subprocess import Popen, PIPE import subprocess
import os from subprocess import Popen, PIPE, STDOUT
import sys
from psutil import Process, TimeoutExpired
import colorama
import six import six
from . import logs, conf, types, shells, custom_fuckups from . import logs, conf, types, shells, custom_fuckups
import getopt import getopt
import sys
import os
def setup_user_dir(): def setup_user_dir():
@ -101,14 +100,17 @@ def get_command(settings):
# - no need for alias with that ^^^ # - no need for alias with that ^^^
# - allows for command line args # - allows for command line args
last_cmd = subprocess.check_output("bash fc -ln -1; history -r", shell=True) shell_cmd = "bash -c -i 'history -r; history -p \!\!'"
event = Popen(shell_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
args = last_cmd.split() output = event.communicate()
args = output.split()
if six.PY2: if six.PY2:
script = ' '.join(arg.decode('utf-8') for arg in args) script = ' '.join(arg.decode('utf-8') for arg in args[1:])
else: else:
script = ' '.join(args) script = ' '.join(args[1:])
if not script: if not script:
return return