2020-10-28 20:21:29 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
# this script logs a new entry in nomie - https://nomie.app/ - an open source habit tracker and journaling app
|
|
|
|
# It will very simply take the text input and pass it on.
|
|
|
|
|
2021-03-30 20:21:42 +00:00
|
|
|
getapikey() {
|
|
|
|
if [ -n "$NOMIE_API_KEY_CMD" ]; then
|
|
|
|
# shellcheck disable=2005
|
|
|
|
echo "$($NOMIE_API_KEY_CMD)"
|
|
|
|
elif [ -n "$NOMIE_API_KEY" ]; then
|
|
|
|
echo "$NOMIE_API_KEY"
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-10-28 20:21:29 +00:00
|
|
|
sendtonomie() {
|
2021-03-30 20:21:42 +00:00
|
|
|
apikey=$(getapikey)
|
|
|
|
if [ "$?" -eq 1 ]; then
|
|
|
|
echo "No api key found."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
req="{\"note\":\"$*\",\"api_key\":\"$apikey\"}"
|
|
|
|
echo "$req"
|
|
|
|
curl -s -H "Content-Type: application/json" --compressed --data "$req" https://nomieapi.com/log
|
2020-10-28 20:21:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 20:21:42 +00:00
|
|
|
usage() {
|
|
|
|
printf """
|
|
|
|
simple nomie logging script.
|
|
|
|
|
|
|
|
usage: nomie \"note content to upload to nomie with #tags and +mentions\"
|
|
|
|
|
|
|
|
Will upload the content passed in on to nomie, using your api key.
|
|
|
|
Set you api key through the \"NOMIE_API_KEY=<my-api-key-here>\" env var,
|
|
|
|
or set a function to return the api key from \"NOMIE_API_KEY_CMD=<my-cmd>\" which will
|
|
|
|
be used preferentially.
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
|
|
|
# print super basic help
|
|
|
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$#" -eq 0 ]; then
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-10-28 20:21:29 +00:00
|
|
|
sendtonomie "$@"
|