aboutsummaryrefslogtreecommitdiff
path: root/edit.py
diff options
context:
space:
mode:
Diffstat (limited to 'edit.py')
-rw-r--r--edit.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/edit.py b/edit.py
new file mode 100644
index 0000000..42f966f
--- /dev/null
+++ b/edit.py
@@ -0,0 +1,46 @@
+# Open your $EDITOR to compose a message in weechat
+#
+# Usage:
+# /edit
+#
+# History:
+# 10-18-2015
+# Version 1.0.0: initial release
+
+import os
+import os.path
+import subprocess
+import weechat
+
+
+def edit(data, buf, args):
+ editor = os.environ.get("EDITOR", "vim")
+ path = os.path.expanduser("~/.weechat/message.txt")
+ open(path, "w+")
+
+ cmd = [editor, path]
+ code = subprocess.Popen(cmd).wait()
+ if code != 0:
+ weechat.command(buf, "/window refresh")
+ return weechat.WEECHAT_RC_ERROR
+
+ with open(path) as f:
+ text = f.read()
+ weechat.buffer_set(buf, "input", text)
+ weechat.buffer_set(buf, "input_pos", str(len(text)))
+
+ weechat.command(buf, "/window refresh")
+
+ return weechat.WEECHAT_RC_OK
+
+
+def main():
+ if not weechat.register("edit", "Keith Smiley", "1.0.0", "MIT",
+ "Open your $EDITOR to compose a message", "", ""):
+ return weechat.WEECHAT_RC_ERROR
+
+ weechat.hook_command("edit", "Open your $EDITOR to compose a message", "",
+ "", "", "edit", "")
+
+if __name__ == "__main__":
+ main()