about summary refs log tree commit diff stats
path: root/bash/moon-maker/mm
blob: ee66c5e11e53c483cd0cdc9d464bc4ae70ed908a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/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 "$@"