Skip to content

Instantly share code, notes, and snippets.

@gcmurphy
Created July 11, 2014 02:21
Show Gist options
  • Save gcmurphy/d213f0b17172814156e1 to your computer and use it in GitHub Desktop.
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'
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