mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 10:11:14 +00:00
Tested edit command
This commit is contained in:
parent
3c1fa55ee1
commit
d43bff511c
@ -3,7 +3,6 @@ import os
|
|||||||
import shlex
|
import shlex
|
||||||
import six
|
import six
|
||||||
import tempfile
|
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
|
||||||
@ -130,16 +129,25 @@ 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
|
||||||
edited_command = None
|
|
||||||
editor = os.getenv("EDITOR", "vi")
|
editor = os.getenv("EDITOR", "vi")
|
||||||
|
|
||||||
with tempfile.TemporaryFile(prefix="the_fuck/command_edit__") as fp:
|
tf = tempfile.NamedTemporaryFile(
|
||||||
# open named temp file in default editor
|
prefix="the_fuck-command_edit__",
|
||||||
fp.write(b'{}'.format(command))
|
suffix=".tmp",
|
||||||
call([editor, fp.name])
|
delete=False)
|
||||||
edited_command = fp.read()
|
tf.write(command.encode('utf8'))
|
||||||
|
tf.close()
|
||||||
|
|
||||||
return edited_command
|
os.system(u"{} '{}' >/dev/tty".format(editor, tf.name))
|
||||||
|
|
||||||
|
tf = open(tf.name, 'r')
|
||||||
|
edited_message = tf.read()
|
||||||
|
tf.close()
|
||||||
|
|
||||||
|
os.unlink(tf.name)
|
||||||
|
|
||||||
|
return edited_message
|
||||||
|
|
||||||
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