Created
April 17, 2017 05:30
-
-
Save danzimm/d68cb597050d3e4076bbf64dfa39f3d4 to your computer and use it in GitHub Desktop.
Weechat cowsay plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import weechat | |
rawCowfiles = subprocess.check_output("cowsay -l", shell=True) | |
cowfiles = [f for line in filter(lambda line: not line.startswith("Cow files in"), rawCowfiles.splitlines()) for f in line.split()] | |
ordCowfiles = "||".join(cowfiles) | |
weechat.prnt("", "Available cowfiles: " + str(cowfiles)) | |
def cowsay(data, buffer, args): | |
command = "fortune | cowsay" | |
if args is not None and len(args) != 0: | |
words = args.split() | |
arg = words[0] | |
if arg in cowfiles: | |
command += " -f " + arg | |
message = subprocess.check_output(command, shell=True) | |
weechat.command(weechat.current_buffer(), message) | |
return weechat.WEECHAT_RC_OK | |
weechat.register("cowsay", "DanZimm", "0.1", "", "Send a fortune cowsay", "", "") | |
weechat.hook_command("cowsay", "Send `fortune | cowsay` to the current buffer", "[cowfile]", "cowfile - the cowfile to use to display the cow. optional", ordCowfiles, "cowsay", "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment