~eli_oat/moon-maker

6ac6c24e9a410616a3c7d340261ecfffe2019433 — eli_oat 1 year, 4 months ago
*
5 files changed, 332 insertions(+), 0 deletions(-)

A .gitignore
A LICENSE
A README.md
A earth-rise.png
A mm
A  => .gitignore +88 -0
@@ 1,88 @@
# Created by https://www.toptal.com/developers/gitignore/api/macos,emacs
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,emacs

### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/
dist/

# Flycheck
flycheck_*.el

# server auth directory
/server/

# projectiles files
.projectile

# directory configuration
.dir-locals.el

# network security
/network-security.data


### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

# End of https://www.toptal.com/developers/gitignore/api/macos,emacs
\ No newline at end of file

A  => LICENSE +21 -0
@@ 1,21 @@
MIT License

Copyright (c) 2024 eli_oat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file

A  => README.md +37 -0
@@ 1,37 @@
# Moon maker

![Dithered version of the iconic "earth rise" image for earth coming up over the moon.](earth-rise.png)

Moon maker, `mm`, helps you add and managing orbiting moon files to central planet files. Useful for documentation, scratch, and explorations while you work. 

This honestly isn't intended for use by other folks, but, I thought it'd be fun to share.

To use `mm`:

- clone this repository
- ensure that `mm` is executable, `chmod +x mm`
- plop the `mm` script someplace in your path
- run `mm -init` at the root of your project, like you would with git.
- from there, you are good to start adding moons to planets!

```plaintext
    Moon Maker

    ⋆。°✩ ☾

    mm is a small program that lets you add orbiting moons to existing planets.

    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 files
                    -l(ist)....list all moons for a given planet file
                    -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
```

`mm -init` creates a folder called `.moons` -- this is where all moons you add to a project live. I like tracking my `.moons` folder in git so that stuff syncs too.
\ No newline at end of file

A  => earth-rise.png +0 -0
A  => mm +186 -0
@@ 1,186 @@
#!/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 files
                    -l(ist)....list all moons for a given planet file
                    -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 [[ ! -d ".moons" ]]; then
        mkdir ".moons"
        echo -e "moons initialized"
    else
        echo -e "there's already a moon directory here"
    fi
    exit
elif [[ "${1-}" =~ ^-*o(pen)?$ ]]; then
    $EDITOR "$2"
    open-moons "$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
    NEW_MOON="$2"."$SHORT_RAND"."$FILE_TYPE"
    add-moons "$NEW_MOON" "$2"
    exit
elif [[ "${1-}" =~ ^-*l(ist)?$ ]]; then
    list-moons-by-planet "$2"
    exit
elif [[ "${1-}" =~ ^-*d(elete)?$ ]]; then
    delete-moon-by-moon-id "$2"
    exit
elif [[ "${1-}" =~ ^-*c(lear)?$ ]]; then
    delete-moons-by-planet "$2"
    exit
elif [[ "${1-}" =~ ^-*u(pdate)?$ ]]; then
    mv "$2" "$3"
    rename-planet-and-orbiting-moons "$2" "$3"
    exit
fi

cd "$(dirname "$0")"

main() {
    echo -e '
    Moon Maker

    ⋆。°✩ ☾

    mm is a small program that lets you add orbiting moons to existing planets.'
    help_text "$@"
}

main "$@"
\ No newline at end of file