mood (1223B)
- #!/bin/sh
- # Copyright 2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
- # Distributed under the terms of the ISC license
- moods_dir="$HOME/moods"
- git_auto_push="true"
- use_git="true"
- die() {
- if [ -n "$*" ]
- then echo "${*}, exiting…" >&2
- else echo "Failed, exiting…" >&2
- fi
- exit
- }
- mood_new() {
- date="$(date +%F)"
- cd "${moods_dir}"
- printf \
- "%s %s\n" \
- "$(date --rfc-3339=seconds)" \
- "$(echo -n "$*" | sed -e 's/^new //')" \
- >> "${date}.log" || die
- if $use_git
- then
- git add "${date}.log" || die
- git commit -m "${date}.log: Updated with mood new" || die
- if $git_auto_push
- then
- git push
- fi
- fi
- }
- mood_check() {
- date="$(date +%F)"
- if [ ! -e "${moods_dir}/${date}.log" ]
- then
- echo "mood: Please input your mood of the day. :3"
- fi
- }
- mood_usage() {
- cat >&2 <<EOF
- Usage: ${1} [new mood_description|check|show|list]
- Subcommands:
- new: inserts a new mood
- check: Reminds you to input your daily mood if not done
- show: show the mood(s) of the day
- list: list the mood(s) files
- EOF
- }
- case $1 in
- 'new')
- mood_new $*
- ;;
- 'check')
- mood_check
- ;;
- 'show')
- ${PAGER:-more} "${moods_dir}/${date}.log"
- ;;
- 'list')
- ls "${moods_dir}"
- ;;
- *)
- mood_usage $0
- exit 1
- ;;
- esac