Better beermeter
[mirrors/Programs.git] / c / beermeter / beermeter.sh
CommitLineData
1e697494
TM
1#!/bin/sh
2title='Beer-O-Meter'
3accounts='./accounts'
2f17eaa1 4totals="$accounts/.totals"
1e697494
TM
5backend='./audio.sh'
6tmp="/tmp/beertmp-$$";
7dialog=$(which dialog);
8
9beer_stat() {
10 echo $(wc -c "$accounts/$1" | cut -d ' ' -f 1) piv
11}
12
13add_account() {
14 "$dialog" --inputbox "New account name" 0 0 2>"$tmp"
15 [ $? = 0 ] && touch "$accounts/$(cat "$tmp")";
16}
17
18servis_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)
2f17eaa1
TM
27 clear
28 echo "=== Totals ($totals) ==="
29 echo
30 cat "$totals"
31 echo
1e697494
TM
32 exit
33 ;;
34 esac
35}
36
37beer_menu() {
2f17eaa1 38 echo -n > "$totals"
1e697494
TM
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"
2f17eaa1 42 echo -e "$i\t$(beer_stat "$i")" >> "$totals"
1e697494
TM
43 done | xargs -0 $dialog --menu "$title stamgasti" 0 0 0
44}
45
46main_menu() {
47 while true; do
48 beer_menu 2>"$tmp"
49 [ "$?" = "0" ] && {
50 stamgast="$(cat "$tmp")"
2f17eaa1 51 clear
1e697494
TM
52 echo == Cepuje stamgast $stamgast, ukonci ctrl+c ==
53 "$backend" | tee -a "$accounts/$stamgast"
54 true
55 } || servis_menu
56 done
57}
58
59main_menu
This page took 0.156976 seconds and 4 git commands to generate.