#!/bin/sh NC='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' msg_info() { echo -e "${GREEN}$1${NC}" } msg_warn() { echo -e "${YELLOW}$1${NC}" } msg_error() { echo -e "${RED}$1${NC}" } print_help() { echo echo "joyce - record your consciousness with ease." echo echo "USAGE:" echo " joyce COMMAND [OPTION...]" echo echo "COMMANDs are:" echo " n | new {title}:" echo " create a new note, setting the title to {title} if provided." echo " This is the default command." echo " h | help:" echo " print this help" echo echo "OPTIONs for 'new' are:" echo " -c | --clipboard:" echo " grab a URL from the clipboard." echo " -u | --url {url}:" echo " pass a URL from command line." echo } BASE="$GIT/stream" STREAM="$BASE/stream.txt" COMMAND=${1:-new} [[ $# -ge 1 ]] && shift CLIPBOARD=0 URL="" while [ $# != 0 ] do arg=$1 case "$arg" in -c|--clipboard) CLIPBOARD=1 ;; -u|--url) [[ $# -gt 1 ]] &&\ URL=$2 &&\ shift ;; *) msg_error "$1: invalid option" print_help exit 1 ;; esac shift done case $COMMAND in n|new) pushd "$BASE" # Sync notes git pull origin master # Add new note DATE="$(date --iso-8601=seconds)" LINE="$DATE\t" if [ "$CLIPBOARD" -eq 1 ]; then CLIP="" if which xclip >/dev/null 2>&1 ; then CLIP="$(xclip -out -selection clipboard)" elif which termux-clipboard-get >/dev/null 2>&1 ; then CLIP="$(termux-clipboard-get)" fi LINE="$LINE[<++>]($CLIP)" elif [ -n "$URL" ]; then LINE="$LINE[<++>]($URL)" fi LINE="$LINE<++>" echo -e "$LINE" >> "$STREAM" nvim + +startinsert "$STREAM" # Sync notes back git add "$STREAM" git commit -m "[$DATE] Update notes" git push origin master ;; help) print_help ;; *) msg_error "$COMMAND: invalid command" print_help exit 2 ;; esac exit 0