Add extra participants (email taken as From field) with
argument +NAME.
-If input is empty, also list of particiants is printed.
+If no input is provided, instead list a summary particiants is printed.
echo | event-participant
CACHE="$HOME/.cache/${0##*/}/events.csv"
HEADER="participant,date_att,date_cancel"
+if [ ! -f "$CACHE" ]; then
+ mkdir -p $(dirname "$CACHE")
+ echo -n "" > "$CACHE"
+fi
+
if [[ "$1" == "--help" ]]; then
echo -e "$HELP" 1>&2
exit 0
shift
fi
-arg_event="$1"
-
-if [ -f "$CACHE" ]; then
- event=$(tail -1 "$CACHE")
+if [ -n "$1" ]; then
+ event="$1"
+ if [ "$event" != "$(tail -1 "$CACHE")" ];then
+ echo "$event" >> "$CACHE"
+ fi
else
- mkdir -p $(dirname "$CACHE")
- echo -n "" > "$CACHE"
+ event=$(tail -1 "$CACHE")
fi
-if [ -n "$arg_event" -a "$arg_event" != "$event" ]; then
- event="$arg_event"
- echo "$event" >> "$CACHE"
+
+if [ ! -f "$event" ]; then
+ echo -n > "$event"
fi
-if [ -z "$event" ]; then
- echo "${0##*/}: E: No event file." 1>&2
- exit 1
+
+# Print summary, if no input data provided
+
+if test -t 0; then
+ n_t=$(cat "$event" | grep -v "$HEADER"| cut -d, -f2 | grep -v '^$' | wc -l)
+ n_c=$(cat "$event" | grep -v "$HEADER"| cut -d, -f3 | grep -v '^$' | wc -l)
+ n_p=$(( $n_t - $n_c ))
+ if [ -z "$info" ]; then
+ cat "$event" | tr ',' '\t'
+ fi
+ echo -ne "At $event:\n part: $n_p\n canc: $n_c\n" 1>&2
+ exit 0
fi
# Add info, sorted by date and uniq
grep -v "^$" \
> "$event.sorted"
mv "$event.sorted" "$event"
-
-# Print summary
-
-n_t=$(cat "$event" | grep -v "$HEADER"| cut -d, -f2 | grep -v '^$' | wc -l)
-n_c=$(cat "$event" | grep -v "$HEADER"| cut -d, -f3 | grep -v '^$' | wc -l)
-n_p=$(( $n_t - $n_c ))
-echo -ne "At $event:\n part: $n_p\n canc: $n_c\n" 1>&2
-if [ -z "$info" ]; then
- cat "$event" | tr ',' '\t'
-fi