logo

mood

A mood-tracker in a POSIX Shell Script.
commit: 00c3c84f9e2ef192f012815d26e90fe66e89380b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 13 Aug 2018 03:25:36 +0200

Initial Commit

Diffstat:

ALICENSE13+++++++++++++
AREADME.md17+++++++++++++++++
Amood71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2018, Haelwenn (lanodan) Monnier <contact@hacktivis.me> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md @@ -0,0 +1,17 @@ +# mood + +A mood-tracker in POSIX Shell Script. + +## Usage +Please modify ``moods_dir`` and ``git_auto_push`` into ``mood`` to the appropriate values for your usage. + +``` +Usage: mood [new mood_description|check] +Subcommands: + new: inserts a new mood + check: Reminds you to input your daily mood if not done +``` + +## Dependencies +* POSIX system: required +* git: recommended, used for syncing between devices diff --git a/mood b/mood @@ -0,0 +1,71 @@ +#!/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] +Subcommands: + new: inserts a new mood + check: Reminds you to input your daily mood if not done +EOF +} + +case $1 in + 'new') + mood_new $* + ;; + 'check') + mood_check + ;; + *) + mood_usage $0 + exit 1 + ;; +esac