Skip to content

Instantly share code, notes, and snippets.

@danzimm
Created April 17, 2017 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danzimm/d68cb597050d3e4076bbf64dfa39f3d4 to your computer and use it in GitHub Desktop.
Save danzimm/d68cb597050d3e4076bbf64dfa39f3d4 to your computer and use it in GitHub Desktop.
Weechat cowsay plugin
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