This commit is contained in:
Case Duckworth 2020-04-11 22:06:43 +00:00
parent bb86f973a3
commit 1aa1496b0d
1 changed files with 50 additions and 6 deletions

View File

@ -8,6 +8,14 @@
#shellcheck disable=1091 #shellcheck disable=1091
. /bread/site/lib.sh . /bread/site/lib.sh
groupck()
{
groups "$USER" | grep -q "$1" || {
echo "You're not in the $1 group!"
exit 3
}
}
usage() usage()
{ {
cat <<-ENDOFUSAGE cat <<-ENDOFUSAGE
@ -50,10 +58,7 @@ bread_news()
cmd="grep -R \"$OPTARG\" \"$BREADNEWS\" -l" cmd="grep -R \"$OPTARG\" \"$BREADNEWS\" -l"
;; ;;
w) w)
groups "$USER" | grep -q admin || { groupck admin
echo "You're not an admin!"
exit 3
}
article="$BREADNEWS/$(date +%F)@$(date +%H:%M).md" article="$BREADNEWS/$(date +%F)@$(date +%H:%M).md"
cat <<-ENDOFARTICLE >"$article" cat <<-ENDOFARTICLE >"$article"
title title
@ -80,10 +85,18 @@ bread_news()
bread_docs() bread_docs()
{ {
while getopts hs:w opt; do while getopts hs:ne: opt; do
case "$opt" in case "$opt" in
h) h)
cat <<-ENDOFHELP cat <<-ENDOFHELP
bread docs : read helpful documents
usage: bread docs [-s QUERY] [-n] [-e QUERY]
-s QUERY search for QUERY in documents
-n write a new document
: if it has the same name as another,
: it'll fail
-e QUERY edit a document matching QUERY
ENDOFHELP ENDOFHELP
exit exit
;; ;;
@ -97,7 +110,37 @@ bread_docs()
echo " 🍞 🥖 🥐 " echo " 🍞 🥖 🥐 "
return return
;; ;;
w) n)
groupck bakers
doc="$(mktemp)"
cat <<-ENDOFDOC >"$doc"
title
author $USER
ENDOFDOC
$EDITOR "$doc"
fname="$BREADDOCS/$(M title "$doc"|slugify).md"
[[ "$fname" =~ */.md ]] && return
if [ -f "$fname" ]; then
echo "$fname already exists!"
echo "Your article is still at $doc."
exit 4
else
cp "$doc" "$fname"
fi
return
;;
e)
groupck bakers
matches=( $(grep -R "$OPTARG" "$BREADDOCS" -l) )
if [[ "${#matches[@]}" -eq 1 ]]; then
$EDITOR "${matches[0]}"
return
fi
select doc in "${matches[@]}"; do
[ "$REPLY" = q ] && return
$EDITOR "$doc"
return
done
;; ;;
\?) return 2 ;; \?) return 2 ;;
*) return 2 ;; *) return 2 ;;
@ -105,6 +148,7 @@ bread_docs()
done done
select doc in "$BREADDOCS"/*; do select doc in "$BREADDOCS"/*; do
[ "$REPLY" = q ] && return
echo " 🍞 🥖 🥐 " echo " 🍞 🥖 🥐 "
printf '\033[34;1;4m%s\033[0m\n' "$(M title "$doc")" printf '\033[34;1;4m%s\033[0m\n' "$(M title "$doc")"
printf '\033[34;1m%s\033[0m\n' "$(M date "$doc")" printf '\033[34;1m%s\033[0m\n' "$(M date "$doc")"