diff --git a/Formula/cowponder.rb b/Formula/cowponder.rb index 299d164..a385ba1 100644 --- a/Formula/cowponder.rb +++ b/Formula/cowponder.rb @@ -1,8 +1,8 @@ class Cowponder < Formula desc "Simple terminal command to display random philosophical thoughts from a cow" homepage "https://github.com/maxcai314/homebrew-cowponder" - url "https://xz.ax/cowponder-homebrew-v0.0.2.tar.gz" - sha256 "9982527b45425239ba0bdce963ec225ea65540185e970ced03fbf27cda350e47" + url "https://max.xz.ax/cowponder/cowponder-homebrew-v0.0.2.tar.gz" + sha256 "a58a046d41044ed6f0b80d35dc9b20301a56b552ef3613bb30a1e38210b73343" depends_on "cowsay" depends_on "python@3" diff --git a/resources/Makefile b/resources/Makefile index 73676f1..a8e4296 100644 --- a/resources/Makefile +++ b/resources/Makefile @@ -1,6 +1,6 @@ CONTENTS_DIR := ./contents BUILD_DIR := . -INSTALL_DIR := /var/www/html +INSTALL_DIR := /var/www/max/cowponder TARBALL_FILE := cowponder-homebrew-v0.0.2.tar.gz .PHONY: all clean install @@ -8,10 +8,10 @@ TARBALL_FILE := cowponder-homebrew-v0.0.2.tar.gz all: $(BUILD_DIR)/$(TARBALL_FILE) install: $(BUILD_DIR)/$(TARBALL_FILE) - cp $(BUILD_DIR)/$(TARBALL_FILE) $(INSTALL_DIR) + cp $^ $(INSTALL_DIR) $(BUILD_DIR)/$(TARBALL_FILE): $(CONTENTS_DIR) - tar -czvf $(BUILD_DIR)/$(TARBALL_FILE) -C $(CONTENTS_DIR) . + tar -czvf $@ -C $^ . shasum -a 256 $(BUILD_DIR)/$(TARBALL_FILE) clean: diff --git a/resources/contents/cowponder b/resources/contents/cowponder index ec6f861..d36ecfd 100755 --- a/resources/contents/cowponder +++ b/resources/contents/cowponder @@ -1,43 +1,78 @@ -#!/usr/bin/env bash - -Help() -{ - echo "cowponder generates an ASCII art picture of a cow thinking some" - echo "fascinating random thoughts. It word-wraps the message at about 40" - echo "columns, and prints the cow saying the given message on standard" - echo "output." - echo "" - echo "cowponder also includes ponder, which provides the same functionality" - echo "but without the bovine centerpiece so users may pipe the thoughts to" - echo "their contemplative creature of choice." - echo "" - echo "Different modes can be enabled by passing the appropriate option." - echo "For instance -d will enable Dead mode, were the cow shown appears" - echo "to be dead. The complete list of options are:" - echo "" - echo " Borg -b" - echo " Dead -d" - echo " Greedy -g" - echo " Paranoid -p" - echo " Stoned -s" - echo " Youthful -y" - echo "" - echo "Outside of the cow modes, there are several additional options. " - echo "Note that these are not available for ponder, since the ponder" - echo "is the same software as cowponder and shares a thoughtbook." - echo " --version, -v Display the version of cowponder and exit." - echo " --update, -u Update the thoughtbook from the interwebs." - echo " This *will* erase any changes you've made; " - echo " back up anything you want to keep!" - echo " --add, -a [thought] Add [thought] to the thoughtbook." -} - -while getopts ":h" option; do - case $option in - h) # display Help - Help - exit;; - esac -done - -cowthink $(ponder "$@") +#!/usr/bin/python3 + +import argparse +import subprocess +from random import SystemRandom +from os import path, popen +cowthoughts_path = path.join(popen("brew --prefix").read().strip(), "etc", "cowthoughts.txt") + +random = SystemRandom() # more random +ap = argparse.ArgumentParser(prog="cowponder", description="""cowponder generates an ASCII art picture of a cow thinking some +fascinating random thoughts. It word-wraps the message at about 40 +columns, and prints the cow saying the given message on standard +output. + +cowponder also includes ponder, which provides the same functionality +but without the bovine centerpiece so users may pipe the thoughts to +their contemplative creature of choice. + +Different modes can be enabled by passing the appropriate option. +For instance -d will enable Dead mode, were the cow shown appears +to be dead. The complete list of options are: + + Borg -b + Dead -d + Greedy -g + Paranoid -p + Stoned -s + Youthful -y + +Outside of the cow modes, there are several additional options. +Note that these are not available for ponder, since the ponder +is the same software as cowponder and shares a thoughtbook. + --help, -h Print this help message and exit. + --version, -v Display the version of cowponder and exit. + --update, -u Update the thoughtbook from the interwebs. + This *will* erase any changes you've made; + back up anything you want to keep! + --add, -a [thought] Add [thought] to the thoughtbook.""", + usage="cowponder [-bdgpsy] [-h] [-v] [-u] [-a ]", formatter_class=argparse.RawDescriptionHelpFormatter, add_help=False) + +ap.add_argument("-v", "--version", action='store_true', help=argparse.SUPPRESS) +ap.add_argument("-u", "--update", action='store_true', help=argparse.SUPPRESS) +ap.add_argument("-a", "--add", help=argparse.SUPPRESS) +ap.add_argument("-h", "--help", action="store_true", help=argparse.SUPPRESS) +arglist = 'bdgpsy' +for i in arglist: + ap.add_argument("-"+i, action="store_true", help=argparse.SUPPRESS) + + +args = vars(ap.parse_args()) + + +if args["help"]: + print(ap.description) + exit() +if args['version']: + subprocess.run(["cowthink", "cowponder version 0.0.1"]) + # print("cowponder version 0.0.1") + exit() +if args['update']: + subprocess.run(["wget", "-q", "-O", cowthoughts_path, "https://raw.githubusercontent.com/maxcai314/cowponder/master/cowponder_0.0.1-1_all/etc/cowthoughts.txt"]) + subprocess.run(["cowthink", "updated thoughtbook"]) + exit() +if thought := args['add']: + with open(cowthoughts_path, "a") as f: + print(thought, file=f) + subprocess.run(['cowthink', '"' + thought + '" added to thoughtbook']) + exit() + + +with open(cowthoughts_path) as thinkbook: + thought = random.choice([thought for thought in thinkbook.read().split("\n") if thought]) + +prefix = "".join([i for i in arglist if args[i]]) +if len(prefix) > 0: + subprocess.run(["cowthink", "-"+prefix, thought]) +else: + subprocess.run(["cowthink", thought]) \ No newline at end of file diff --git a/resources/contents/ponder b/resources/contents/ponder index c19fb12..c190993 100755 --- a/resources/contents/ponder +++ b/resources/contents/ponder @@ -4,6 +4,9 @@ import argparse import subprocess import os from random import SystemRandom +from os import path, popen +cowthoughts_path = path.join(popen("brew --prefix").read().strip(), "etc", "cowthoughts.txt") + random = SystemRandom() # more random cowthoughts_file = os.path.join(os.popen("brew --prefix").read().strip(), "etc", "cowthoughts.txt") @@ -12,36 +15,24 @@ ap = argparse.ArgumentParser(prog="ponder", description="provides the functional ap.add_argument("-v", "--version", action='store_true', help="Print version information and exit.") ap.add_argument("-u", "--update", action='store_true', help="Update thoughtbook from the server. This *will* overwrite any changes made with cowponder --add.") ap.add_argument("-a", "--add", help="Add custom thought to thoughtbook.") -# ap.add_argument("pipe_args", action='append', nargs='*', help='any additional arguments which should be included in the output, for whatever the next command is.') -ap.add_argument("-b", action='store_true', help=argparse.SUPPRESS) -ap.add_argument("-d", action='store_true', help=argparse.SUPPRESS) -ap.add_argument("-g", action='store_true', help=argparse.SUPPRESS) -ap.add_argument("-p", action='store_true', help=argparse.SUPPRESS) -ap.add_argument("-s", action='store_true', help=argparse.SUPPRESS) -ap.add_argument("-y", action='store_true', help=argparse.SUPPRESS) args = vars(ap.parse_args()) if args['version']: print("cowponder version 0.0.1") exit() if args['update']: - subprocess.run(["wget", "-O", cowthoughts_file, "https://raw.githubusercontent.com/maxcai314/cowponder/master/cowponder_0.0.1-1_all/etc/cowthoughts.txt"]) + subprocess.run(["wget", "-q", "-O", cowthoughts_path, "https://max.xz.ax/cowponder/cowthoughts.txt"]) print("updated thoughtbook (moo)") exit() -if not ((thought := args['add']) is None): - with open(cowthoughts_file, "a") as thinkbook: - print(thought, file=thinkbook) - -prefix = '' -if args['b']: prefix += ' -b ' -if args['d']: prefix += ' -d ' -if args['g']: prefix += ' -g ' -if args['p']: prefix += ' -p ' -if args['s']: prefix += ' -s ' -if args['y']: prefix += ' -y ' - -with open(cowthoughts_file) as thinkbook: +if thought := args['add']: + with open(cowthoughts_path, "a") as f: + print(thought, file=f) + print('"', thought, '" added to thoughtbook (moo)', sep='') + exit() + + +with open(cowthoughts_path) as thinkbook: thoughts = [thought for thought in thinkbook.read().split("\n") if thought] thought = random.choice(thoughts) -print(prefix + thought) +print(thought) diff --git a/resources/cowponder-homebrew-v0.0.2.tar.gz b/resources/cowponder-homebrew-v0.0.2.tar.gz index 1f7253d..fb51a59 100644 Binary files a/resources/cowponder-homebrew-v0.0.2.tar.gz and b/resources/cowponder-homebrew-v0.0.2.tar.gz differ