#!/usr/bin/env bash set -o errexit set -o nounset set -o pipefail if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace fi EDITOR="subl -n -b" add-moons () { if [[ -d ".moons" ]]; then touch ".moons/$1" echo -e "a new moon is orbiting $2" else path=$(pwd) while [ -n "$path" ]; do path=${path%/*} if [ -d "$path/.moons" ]; then touch "$path/.moons/$1" echo -e "a new moon is orbiting $2" return fi done fi } delete-moon-by-moon-id () { if [[ -d ".moons" ]]; then rm .moons/*"$1"* echo -e "the moon $1 has been removed" else path=$(pwd) while [ -n "$path" ]; do path=${path%/*} if [ -d "$path/.moons" ]; then rm "$path/.moons/"*"$1"* echo -e "the moon $1 has been removed" return fi done fi } delete-moons-by-planet () { if [[ -d ".moons" ]]; then rm .moons/"$1"* echo -e "all moons orbiting $1 have been deleted." else path=$(pwd) while [ -n "$path" ]; do path=${path%/*} if [ -d "$path/.moons" ]; then rm "$path/.moons/$1"* echo -e "all moons orbiting $1 have been deleted." return fi done fi } open-moons () { if [[ -d ".moons" ]]; then for file in .moons/$1; do echo -e "$file" $EDITOR "$file" done else path=$(pwd) while [ -n "$path" ]; do path=${path%/*} if [ -d "$path/.moons" ]; then for file in $path/.moons/$1; do echo -e "$file" $EDITOR "$file" done return fi done fi } list-moons-by-planet () { if [[ -d ".moons" ]]; then ls -a .moons/"$1"* else path=$(pwd) while [ -n "$path" ]; do path=${path%/*} if [ -d "$path/.moons" ]; then ls -a "$path/.moons/$1"* return fi done fi } rename-planet-and-orbiting-moons () { if [[ -d ".moons" ]]; then for file in .moons/"$1"* ; do mv "$file" "${file//$1/$2}" ; done echo -e "planets and moons have been renamed from $1 to $2" else path=$(pwd) while [ -n "$path" ]; do path=${path%/*} if [ -d "$path/.moons" ]; then for file in "$path/.moons/$1"* ; do mv "$file" "${file//$1/$2}" ; done echo -e "planets and moons have been renamed from $1 to $2" return fi done fi } PRE_SHORT_RAND=$(openssl rand -base64 6) SHORT_RAND=${PRE_SHORT_RAND//\//_} help_text() { echo ' A planet file is the one you care about -- probably an file in an actual 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 file