2005/01/07

Bash humor quotes database aids

#!/bin/bash

FORTFILE=/home/rodolfoap/bin/fortunes.mine
EDITOR=vi

HLPTXT=$(cat <<EOT
GNU fortunes is a personal fortunes engine organizer, written in bash.

Usage: fortunes [OPTION]

Options:
-e edit fortunes file
-l enters learning mode
-m enters multiline-learning mode
--help shows this help
--version shows version

Examples:

fortunes --help shows this help
fortunes -e edits fortunes file
fortunes generates a random fortune
fortunes -l starts learning mode

Report bugs to rodolfoap@hotmail.com
EOT)

VERTXT=$(cat <<EOT
GNU fortunes v0.1

Copyright (C) 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Written by Rodolfo Alcazar
EOT)

case "$1" in
"")
fortune $FORTFILE
;;
"-e")
$EDITOR $FORTFILE
/usr/sbin/strfile $FORTFILE
echo
;;
"-l")
echo "Entering learning mode."
echo
read -p "> " QUE
echo -e "$QUE\n%" >> $FORTFILE
echo
/usr/sbin/strfile $FORTFILE
;;
"-m")
echo "Entering multiline learning mode. End questions and answers with ^D."
echo
echo -n "> "
QUE=$(cat)
echo -e "$QUE\n%" >> $FORTFILE
echo
/usr/sbin/strfile $FORTFILE
;;
"-h"|"--help")
echo "$HLPTXT"
;;
"-v"|"--version")
echo "$VERTXT"
;;
esac



Fun, hah? With this basics I've wrote a flashcards studying tool. Drop me a line if you want it. Even better, you can write your own!

No comments: