From 0f3e148fd3d063f8c8c9d59d630768b5cfadd5b7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 11 Apr 2020 20:21:05 +0000 Subject: [PATCH] Change time signature --- bread/bin/bread | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/bread/bin/bread b/bread/bin/bread index 5ecb150..ab33ea3 100755 --- a/bread/bin/bread +++ b/bread/bin/bread @@ -17,14 +17,55 @@ usage() 🍞 🥖 🥐 commands: - news: read the news + + for detailed usage of each command, + run bread COMMAND -h + 🍞 🥖 🥐 ENDOFUSAGE exit 1 } bread_news() { - n="${1:-4}" - for art in $(find "$BREADNEWS" -type f | sort -nr | head -n"$n"); do + num=4 + while getopts hn:s:w opt; do + case "$opt" in + h) + cat <<-ENDOFHELP + bread news : read the news + usage: bread news [-n NUM] [-s QUERY] [-w] + + -n NUM read NUM newest articles. default: 4 + -s QUERY search for QUERY in news database + -w write a new article (admin only) + ENDOFHELP + exit + ;; + n) num="$OPTARG" ;; + s) + query="$OPTARG" + ;; + w) + groups "$USER" | grep -q admin || { + echo "You're not an admin!" + exit 3 + } + article="$BREADNEWS/$(date +%F)@$(date +%H:%M).md" + cat <<-ENDOFARTICLE >"$article" + title + author $USER + date $(date +%F) + + ENDOFARTICLE + $EDITOR "$article" + exit + ;; + \?) return 2 ;; + *) return 2 ;; + esac + done + + for art in $(find "$BREADNEWS" -type f | sort -nr | head -n "$num"); do echo " 🍞 🥖 🥐 " printf '\033[34;1;4m%s\033[0m\n' "$(M title "$art")" printf '\033[34;1m%s\033[0m\n' "$(M date "$art")" @@ -45,7 +86,7 @@ main() shift "$((OPTIND - 1))" cmd="$1"; shift - bread_"$cmd" "$@" + bread_"$cmd" "$@" || exit $? } main "$@"