mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 09:39:01 +00:00
Switched to using tempfiles
still need to test this
This commit is contained in:
parent
f96406cd71
commit
3c1fa55ee1
@ -2,6 +2,8 @@ import io
|
|||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
import six
|
import six
|
||||||
|
import tempfile
|
||||||
|
from subprocess import call
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from ..logs import warn
|
from ..logs import warn
|
||||||
from ..utils import memoize
|
from ..utils import memoize
|
||||||
@ -128,21 +130,16 @@ class Generic(object):
|
|||||||
"""Spawn default editor (or `vi` if not set) and edit command in a buffer"""
|
"""Spawn default editor (or `vi` if not set) and edit command in a buffer"""
|
||||||
# Create a temporary file and write some default text
|
# Create a temporary file and write some default text
|
||||||
# mktemp somewhere
|
# mktemp somewhere
|
||||||
file_path = "The Fuck: Command Edit"
|
edited_command = None
|
||||||
with open(file_path, "w") as file_handle:
|
|
||||||
file_handle.write(command)
|
|
||||||
|
|
||||||
editor = os.getenv("EDITOR", "vi")
|
editor = os.getenv("EDITOR", "vi")
|
||||||
|
|
||||||
os.system(u"{} '{}' >/dev/tty".format(editor, file_path))
|
with tempfile.TemporaryFile(prefix="the_fuck/command_edit__") as fp:
|
||||||
|
# open named temp file in default editor
|
||||||
|
fp.write(b'{}'.format(command))
|
||||||
|
call([editor, fp.name])
|
||||||
|
edited_command = fp.read()
|
||||||
|
|
||||||
data = None
|
return edited_command
|
||||||
with open(file_path, "r") as file_handle:
|
|
||||||
data = file_handle.read()
|
|
||||||
|
|
||||||
os.remove(file_path)
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
def get_builtin_commands(self):
|
def get_builtin_commands(self):
|
||||||
"""Returns shells builtin commands."""
|
"""Returns shells builtin commands."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user