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