Created
April 8, 2010 21:42
-
-
Save whitmo/360579 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tempfile, sys, os | |
| def what_editor(): | |
| editor = os.getenv('VISUAL') or os.getenv('EDITOR') | |
| if not editor: | |
| editor = 'vi' | |
| return editor | |
| def get_edited_text(starting_text=''): | |
| temp_fd, temp_fn = tempfile.mkstemp(text=True) | |
| os.write(temp_fd, starting_text) | |
| os.close(temp_fd) | |
| editor = what_editor() | |
| proc = os.spawnlp(os.P_WAIT, editor, editor, temp_fn) | |
| if proc: | |
| raise RuntimeError, "Can't run %s %s" %(editor, temp_fn) | |
| result = open(temp_fn).read() | |
| os.unlink(temp_fn) | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment