Created
July 11, 2014 02:21
-
-
Save gcmurphy/d213f0b17172814156e1 to your computer and use it in GitHub Desktop.
Pops up your $EDITOR and returns the content entered. Similar to 'git commit -a'
This file contains 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
def edit_dialog(**kwargs): | |
EDITOR = os.environ.get("EDITOR", "vim") | |
with tempfile.NamedTemporaryFile(suffix=".tmp") as tmp: | |
if 'prefill' in kwargs: | |
tmp.write(kwargs.get('prefill')) | |
tmp.flush() | |
subprocess.call([EDITOR, tmp.name]) | |
output = "" | |
with open(tmp.name) as message: | |
for line in message: | |
if not line.startswith ('#'): | |
output += line | |
if not output.strip(): | |
return "\n\n\tERROR: Edit aborted by user!\n\n" | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment