-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddrecipe
executable file
·49 lines (36 loc) · 1.21 KB
/
addrecipe
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
#!/bin/bash
FILE=`mktemp -t addrecipe-XXXXXX`
DIALOG=`mktemp -t addrecipe-XXXXXX`
trap "rm -f $FILE $DIALOG" 0 15
HEIGHT=$(($(stty size | cut -f 1 -d " ")-2))
WIDTH=$(($(stty size | cut -f 2 -d " ")-4))
echo -n dialog --menu \"Select a category:\" $HEIGHT $WIDTH $(($HEIGHT-5)) \ > $DIALOG
for each in $(ls -d */)
do
echo -n $each \ >> $DIALOG
if [ -f ${each}name ]
then
echo -n \"$(cat ${each}name | tr -d \'\" )\" \ >> $DIALOG
else
echo -n $each \ | tr -d / >> $DIALOG
fi
done
echo 2\>$FILE >> $DIALOG
. $DIALOG
[ $? == 0 ] || exit 1
CAT="`cat $FILE`"
dialog --inputbox "Recipe name:" $HEIGHT $WIDTH 2>$FILE
[ $? == 0 ] || exit 1
TITLE="`cat $FILE`"
[ "x$TITLE" == "x" ] && exit 1
dialog --inputbox "Recipe author:" $HEIGHT $WIDTH 2>$FILE
[ $? == 0 ] || exit 1
AUTHOR="`cat $FILE`"
dialog --inputbox "Number of servings:" $HEIGHT $WIDTH 2>$FILE
[ $? == 0 ] || exit 1
SIZE="`cat $FILE`"
FILENAME="$CAT$(echo $TITLE | tr A-Z a-z | sed -e 's/^\([a-z]\)/\U\1/g; s/\([^A-Za-z0-9]\)\([a-z]\)/\1\U\2/g' | tr -d " " ).tex"
sed -e 's/name/'"$TITLE"'/g;s/author/'"$AUTHOR"'/g;s/servings/'"$SIZE"'/g' Template.tex > ${FILENAME}
rm -f $FILE $DIALOG
[ "x$EDITOR" == x ] && EDITOR=vi
$EDITOR $FILENAME && git add $FILENAME