diff options
author | Keith Smiley <keithbsmiley@gmail.com> | 2015-10-18 19:24:28 -0700 |
---|---|---|
committer | Keith Smiley <keithbsmiley@gmail.com> | 2015-10-18 19:24:28 -0700 |
commit | 2f6f7e1701cdfc776e469d55c374a2c414e44894 (patch) | |
tree | 4d8525efc11519756e61a807b64d1c140db4d086 | |
download | edit-2f6f7e1701cdfc776e469d55c374a2c414e44894.tar.gz edit-2f6f7e1701cdfc776e469d55c374a2c414e44894.zip |
Initial Commit
-rw-r--r-- | LICENSE | 18 | ||||
-rw-r--r-- | README.md | 21 | ||||
-rw-r--r-- | edit.py | 46 |
3 files changed, 85 insertions, 0 deletions
@@ -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 +``` @@ -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() |