summaryrefslogtreecommitdiff
path: root/src/bin/eet/vieet
blob: 8bfdb4e869b669f5be7ac1cc000f43147e7bf175 (plain)
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
#!/bin/sh

cleanup() {
    if [ ! -z "$TFILE" ]; then
        rm "$TFILE"
    fi
}

die() {
    echo "$@"
    echo "Aborting"
    cleanup
    exit 1
}

usage() {
    die "Usage: vieet <eet file> [section]"
}

EETFILE="$1"
SECTION="$2"

if [ $# -eq 1 ]; then
    eet -l "$EETFILE"
    exit $?
fi

if [ $# -ne 2 ]; then
    usage
fi

if [ -z "$EDITOR" ]; then
    die "EDITOR env var must be set."
fi

TFILE=$(mktemp)

if [ $? -ne 0 ]; then
    die "Failed creating tempfile."
fi

# Decode the file
eet -d "$EETFILE" "$SECTION" "$TFILE"

if [ $? -ne 0 ]; then
    die "Failed decoding eet file."
fi

DONE=0

while [ $DONE -ne 1 ]
do
    $EDITOR $TFILE

    eet -e "$EETFILE" "$SECTION" "$TFILE" 1
    if [ $? -ne 0 ]; then
        echo "Failed compiling eet file."
        echo "Press 'Return' to reopen the editor, or ^C to abort."
        read
    else
        DONE=1
    fi
done

cleanup