aboutsummaryrefslogtreecommitdiff
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
downloadedit-2f6f7e1701cdfc776e469d55c374a2c414e44894.tar.gz
edit-2f6f7e1701cdfc776e469d55c374a2c414e44894.zip
Initial Commit
-rw-r--r--LICENSE18
-rw-r--r--README.md21
-rw-r--r--edit.py46
3 files changed, 85 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..109d98c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,18 @@
+Copyright (c) 2015 Keith Smiley (http://keith.so)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the 'Software'), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..2ddcf04
--- /dev/null
+++ b/README.md
@@ -0,0 +1,21 @@
+# edit-weechat
+
+This simple [weechat](https://weechat.org/) plugin allows you to
+compose messages in your `$EDITOR`.
+
+# Usage
+
+```sh
+/edit
+# Type some stuff
+# Save and quit
+```
+
+# Installation
+
+Copy the script to `~/.weechat/python/autoload`
+
+```
+mkdir -p ~/.weechat/python/autoload
+wget https://raw.githubusercontent.com/keith/edit-weechat/master/edit ~/.weechat/python/autoload
+```
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()