diff --git a/.gitignore b/.gitignore index a923ba7..b306507 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .env nekobot +wishlist.txt diff --git a/scripts/wishlist b/scripts/wishlist new file mode 100755 index 0000000..ec5befe --- /dev/null +++ b/scripts/wishlist @@ -0,0 +1,57 @@ +#!/bin/sh +# +# wishlist records wishlist items + +set -exu + +cmd="$@" +wishlist="wishlist.txt" + +[ -f "$wishlist" ] || touch "$wishlist" + +die() { + printf "%s.\n" "$1" + exit 1 +} + +print_usage() { + printf "%s\n" "!neko wishlist +commands: + add - add a wishlist item + remove - remove a wishlist item + show - show the wishlist + clear - clear the wishlist" + exit 42 +} + +wishlist_add() { + item="$(printf "%s" "$@" | sed -E 's/^add +//g')" + [ -z "$item" ] && die "specify an item to add" + printf "%s\n" "$item" >> wishlist.txt + printf "%s\n" "$item added" +} + +wishlist_remove() { + item="$(printf "%s" "$@" | sed -E 's/^remove +//g')" + [ -z "$item" ] && die "specify an item to remove" + sed -E "s/^$item$//g" -i "$wishlist" + printf "%s\n" "$item removed" +} + +wishlist_show() { + cat "$wishlist" + exit 42 +} + +wishlist_clear() { + printf "" > "$wishlist" + printf "%s\n" "wishlist cleared" +} + +case "$cmd" in + add*) wishlist_add "$@" ;; + remove*) wishlist_remove "$@" ;; + show) wishlist_show ;; + clear) wishlist_clear ;; + *) print_usage ;; +esac