#!/bin/sh

list="$HOME/.collect-files.lst"

case "$1" in
    add)
        ;;
    list)
        test -f "$list" && cat "$list"
        exit
        ;;
    purge)
        test -f "$list" && rm "$list"
        exit
        ;;
    *)
        1>&2 cat <<EOF
Collect filenames into $list
Usage: $0 <action>
  Actions:
  add <filename>.. - add the filenames
  list             - print the list of collected filenames
  purge            - purge the list of collected filenames
EOF
        exit 1
        ;;
esac

shift

while [ ! -z "$1" ]; do
    filename="$1"
    shift
    if [ ! -f "$filename" ]; then
        1>&2 echo "File not found: ${filename}"
        continue
    fi
    echo "$filename" >> "$list"
done
