diff --git a/README.md b/README.md index 328d497..be34227 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ The issue with Anytype (and Notion) is that there are too many clicks needed. While Notion has better automation, I think nothing can beat the functionality of just scripts. That and the fact that I want to have all the files as markdown in case I want to search/collect statistics or plots/process with a local llm inspired this project. +**This is mostly AI generated** + +## Why use AI for this? + +I generally try to avoid AI for personal projects in an attempt to stay mentally sharp and keep my programming skills up. +The functionality here are mainly basic automations that aren't very interesting to do by hand. +Since I want to try and use my time on more interesting problems, I don't feel too bad using AI for these. + ## Functionality and status Here is the list of functionality that I'm working towards. diff --git a/quotes b/quotes new file mode 100755 index 0000000..25c873f --- /dev/null +++ b/quotes @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +set -euo pipefail + +QUOTES_FILE="${QUOTES_FILE:-$HOME/.local/share/os/quotes.txt}" + +usage() { + cat <<'EOF' +Usage: quotes.sh [args] + +Commands: + add Add a quote as: quote {{ author }} + today Print today's deterministic quote +EOF +} + +trim() { + local value="$1" + value="${value#"${value%%[![:space:]]*}"}" + value="${value%"${value##*[![:space:]]}"}" + printf '%s' "$value" +} + +ensure_file() { + mkdir -p "$(dirname "$QUOTES_FILE")" + + if [ ! -e "$QUOTES_FILE" ]; then + touch "$QUOTES_FILE" + fi +} + +add_quote() { + if [ "$#" -ne 2 ]; then + echo 'Usage: quotes.sh add ' >&2 + exit 1 + fi + + ensure_file + + local quote author + quote="$(trim "$1")" + author="$(trim "$2")" + + if [ -z "$quote" ] || [ -z "$author" ]; then + echo 'Quote and author must be non-empty' >&2 + exit 1 + fi + + if [[ "$quote" == *$'\n'* ]] || [[ "$author" == *$'\n'* ]]; then + echo 'Quote and author must be single-line values' >&2 + exit 1 + fi + + if [ -s "$QUOTES_FILE" ] && [ "$(tail -c 1 "$QUOTES_FILE" 2>/dev/null || true)" != $'\n' ]; then + printf '\n' >> "$QUOTES_FILE" + fi + + printf '%s {{ %s }}\n' "$quote" "$author" >> "$QUOTES_FILE" +} + +today_quote() { + ensure_file + + local day hash + day="$(date +%F)" + hash="$(printf '%s' "$day" | cksum | awk '{print $1}')" + + awk -v hash="$hash" ' + NF { lines[count++] = $0 } + END { + if (count == 0) { + exit 1 + } + + line = lines[hash % count] + if (match(line, / \{\{ .* \}\}$/)) { + quote = substr(line, 1, RSTART - 1) + author = substr(line, RSTART) + sub(/^ \{\{ /, "", author) + sub(/ \}\}$/, "", author) + printf "%s\n-- %s\n", quote, author + } else { + print line + } + } + ' "$QUOTES_FILE" || { + echo "No quotes found in $QUOTES_FILE" >&2 + exit 1 + } +} + +case "${1:-}" in + add) + shift + add_quote "$@" + ;; + today|daily) + today_quote + ;; + -h|--help|help) + usage + ;; + *) + usage >&2 + exit 1 + ;; +esac