Better beermeter
[mirrors/Programs.git] / c / beermeter / beermeter.sh
1 #!/bin/sh
2 title='Beer-O-Meter'
3 accounts='./accounts'
4 totals="$accounts/.totals"
5 backend='./audio.sh'
6 tmp="/tmp/beertmp-$$";
7 dialog=$(which dialog);
8
9 beer_stat() {
10 echo $(wc -c "$accounts/$1" | cut -d ' ' -f 1) piv
11 }
12
13 add_account() {
14 "$dialog" --inputbox "New account name" 0 0 2>"$tmp"
15 [ $? = 0 ] && touch "$accounts/$(cat "$tmp")";
16 }
17
18 servis_menu() {
19 $dialog --menu "$title servis" 0 0 0 new "Novy stamgast" exit "Konec party" 2>"$tmp"
20 option="$(cat "$tmp")"
21
22 case $option in
23 new)
24 add_account
25 ;;
26 exit)
27 clear
28 echo "=== Totals ($totals) ==="
29 echo
30 cat "$totals"
31 echo
32 exit
33 ;;
34 esac
35 }
36
37 beer_menu() {
38 echo -n > "$totals"
39 ls -1 --group-directories-first "$accounts" | while read i; do
40 echo -n "$i"; echo -ne "\x00";
41 echo -n $(beer_stat "$i"); echo -ne "\x00"
42 echo -e "$i\t$(beer_stat "$i")" >> "$totals"
43 done | xargs -0 $dialog --menu "$title stamgasti" 0 0 0
44 }
45
46 main_menu() {
47 while true; do
48 beer_menu 2>"$tmp"
49 [ "$?" = "0" ] && {
50 stamgast="$(cat "$tmp")"
51 clear
52 echo == Cepuje stamgast $stamgast, ukonci ctrl+c ==
53 "$backend" | tee -a "$accounts/$stamgast"
54 true
55 } || servis_menu
56 done
57 }
58
59 main_menu
This page took 0.27597 seconds and 4 git commands to generate.