Skip to content

Commit

Permalink
Tested edit command
Browse files Browse the repository at this point in the history
  • Loading branch information
cjoshmartin authored and scorphus committed May 10, 2020
1 parent 3c1fa55 commit d43bff5
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions thefuck/shells/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import shlex
import six
import tempfile
from subprocess import call
from collections import namedtuple
from ..logs import warn
from ..utils import memoize
Expand Down Expand Up @@ -130,16 +129,25 @@ def edit_command(self, command):
"""Spawn default editor (or `vi` if not set) and edit command in a buffer"""
# Create a temporary file and write some default text
# mktemp somewhere
edited_command = None

editor = os.getenv("EDITOR", "vi")

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()
tf = tempfile.NamedTemporaryFile(
prefix="the_fuck-command_edit__",
suffix=".tmp",
delete=False)
tf.write(command.encode('utf8'))
tf.close()

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_command
return edited_message

def get_builtin_commands(self):
"""Returns shells builtin commands."""
Expand Down

0 comments on commit d43bff5

Please sign in to comment.