aboutsummaryrefslogtreecommitdiff
path: root/edit.py
diff options
context:
space:
mode:
authorKeith Smiley <keithbsmiley@gmail.com>2015-10-18 19:24:28 -0700
committerKeith Smiley <keithbsmiley@gmail.com>2015-10-18 19:24:28 -0700
commit2f6f7e1701cdfc776e469d55c374a2c414e44894 (patch)
tree4d8525efc11519756e61a807b64d1c140db4d086 /edit.py
downloadedit-2f6f7e1701cdfc776e469d55c374a2c414e44894.tar.gz
edit-2f6f7e1701cdfc776e469d55c374a2c414e44894.zip
Initial Commit
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()