Concept

I use the terminal. A lot. As such, I like to have a lot of bells and whistles. One of those is to have my own custom fortune file. Here’s how it’s done:

  1. First, store your fortunes in a text file, say myfortunes, with the fortunes separated by a line containing a single ‘%’ sign, like so:

    fortune one
    %
    fortune two
    % 
    fortune three
    %
  2. Next, parse this file with the strfile utility, included with fortune.

    strfile myfortunes

    this will create a binary file myfortunes.dat.

  3. Invoke fortune as follows

    fortune myfortunes

    where myfortunes is the complete path to your fortune file. Put this line in your .bashrc, and you’re all set!

OS X

Under OS X it’s possible to drag and drop text from almost any application to the desktop. In this case, the text appears as a resource fork of the file in question. I used the following script to batch convert .textClipping files to plain text files:

textclippingcv.sh

#!/bin/bash

# case where no arguments found
if [[ $# = 0 ]]
then
  echo "Usage: textclippingcv [directory] | [inputfile [outputfile]]"
    echo "If the first argument is a directory, textclippingcv will batch process all"
    echo "the .textClippings in that directory, renaming them with .txt"
    echo "If the first argument is a file, textclippingcv will convert that file to "
    echo "one of the same name but with a .txt extention, unless an output"
    echo "file is specified."
    exit
fi

if [[ -z $2 ]]
then
    OUTFILE="${1%%.textClipping}.txt"
else
    OUTFILE=$2
fi
# if two files are given as arguments
if [[ -f $1 ]]
then
    /Developer/Tools/DeRez "$1" -only TEXT | xxd -r -c 8 -p > "${OUTFILE}"
    exit
else 
    if [[ -d $1 ]] && [[ $# = 1 ]]
    then
        cd $1
    for I in *.textClipping
    do
        echo "${I%%.textClipping}" 
        /Developer/Tools/DeRez "$I" -only TEXT | xxd -r -c 8 -p > "${I%%.textClipping}.txt"
    done
        exit
    else
        echo "$1 doesn't appear to be a valid file or directory."
    exit
fi
    echo "$1 doesn't appear to be a valid file or directory."
    exit
fi

This is called from another script which compiles the text clippings and does a litle formatting.

clipping2fortune.sh

#!/bin/bash

# take all of the textclippings on the desktop, and put them into the
# fortune file

cd ~/Desktop
for I in *.textClipping 
do
  if test -a "./$I"
  then 
    # convert them to text
    ~/Scripts/textclippingcv.sh "./$I"
    # have vim format the paragraph
        # like this:
        # remove non-ascii
        # set the fileformat to unix (newlines)
        # make every new line another newline so the paragraph filter works
        # execute the paragraph filter
        # delete all blank lines
        # save
    vim -c "%s/[€-ÿ]//g" -c "argdo set fileformat=unix" -c "g/^/ normal gq$" -c "argdo wq" "./${I%%.textClipping}.txt"
        # put them into the file
    cat "./${I%%.textClipping}.txt" >> ~/Documents/Fortunes/textclippings
    echo "%" >> ~/Documents/Fortunes/textclippings
    #delete them
    rm "./$I"
    rm "./${I%%.textClipping}.txt"
  fi
done

# make the dat file
strfile ~/Documents/Fortunes/textclippings ~/Documents/Fortunes/textclippings.dat