#!/usr/bin/env bash set -o errexit set -o nounset set -o pipefail if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace fi SHORT_RAND=$(openssl rand -base64 6) help_text() { echo ' Moon Maker mm, is a small program that lets you add orbiting moons to planet files. A planet file is one that you care about -- probably an actual file in your project. Moon files orbit planets, they are disposable scratch spaces connected to planets. usage: ./mm -i(nit)....initialize a directory to store moon files -o(pen)....open a planet file and all of its moon files -a(dd).....create a new moon file for a given planet file -d(elete)..remove a moon file by its id -c(lear)...remove all moon files for a given planet file -u(pdate)..rename a planet file and all of its moon files ' } if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then help_text "$@" exit elif [[ "${1-}" =~ ^-*i(nit)?$ ]]; then if [[ -f .mm ]]; then mkdir .mm else echo -e " a moon maker directory already exists so you can't add another one here. " fi elif [[ "${1-}" =~ ^-*o(pen)?$ ]]; then $EDITOR "$2" exit elif [[ "${1-}" =~ ^-*a(dd)?$ ]]; then if [ $# -ge 3 ]; then FILE_TYPE="$3" # optionally pass a file type you'd like to append to the moon else FILE_TYPE="txt" # if you don't provide a file type, assume .txt for the new moon fi echo "$2"."$SHORT_RAND"."$FILE_TYPE" exit elif [[ "${1-}" =~ ^-*d(elete)?$ ]]; then echo "delete" exit elif [[ "${1-}" =~ ^-*c(lear)?$ ]]; then echo "clear" exit elif [[ "${1-}" =~ ^-*u(pdate)?$ ]]; then echo "update" exit fi cd "$(dirname "$0")" main() { help_text "$@" } main "$@"