ph - a simple phone book
Originally for the Amiga, ph was completely
rewritten in August 2000 as a pair of Unix shell
scripts. A third script, phdel, was added 11 February
2004.
Author, copyleft
Written (copyright 2000, 2004) by Chris F.A. Johnson,
and released under the terms of the GNU
General Public License, a.k.a. "copyleft".
Features
- Command-line interface
- Case-insensitive searching
- Can store arbitrary information as well as names and
phone numbers
- Searching can be done for any information
entered
- Phone books can be edited with any text editor
- Just three commands:
ph
phadd
phdel
New in version 0.2
- Extended regular expressions may be used in search
string
- Multiple address books, personal and system-wide
Usage
- ph [-w] <name(s) or number(s) to find>
- phadd [-s] <data to store in phone book>
Options
ph
- -w - match only whole words
e.g., ph -w john
would match “John”, but not “Johnson”
- There are other undocumented options which
add very little (if anything) to the usefulness
of
ph
phadd
- -s - add to system-wide phone book
By default, phadd stores the information in
a user’s personal phone book.
phdel
- -s - remove entry from system-wide phone book
By default, phdel removes the information from
the user's personal phone book.
Examples
- phadd John Doe - 555-4321
- phadd -s "James Jackson - (312) 555-1234"
- phadd Jane Johnson - "(213)" 555-6789
NOTE: characters special to the shell (e.g. "(" and ")")
must be quoted
- ph Jack
James Jackson - (312) 555-1234
- ph -w john
John Doe - 555-4321
- ph -w 'John|James'
James Jackson - (312) 555-1234
John Doe - 555-4321
- ph 555
James Jackson - (312) 555-1234
John Doe - 555-4321
Jane Johnson - (213) 555-6789
Files
- System-wide data file
- /info/data/phones
This is a non-standard directory, and can be changed by altering the
references in each of the scripts.
- Each user has a data file:
- $HOME/.phones
History
These started out as one-liners on the Amiga, where they served
me well for almost 15 years. When I finally put Ami to rest and
moved over to a Linux box, I converted them to Unix shell scripts:
phadd - echo "$*" >> $HOME/.phones
ph - grep -i "$*" $HOME/.phones
I copied the phone file from my Amiga, and it was business as
usual.
Although my computer is primarily a single-user machine, it is on a
LAN, and other people do have accounts on it; therefore, I thought
it would be useful to expand ph so that it could be used by
everyone.
The changes required were very simple:
- add a generally accessible file to contain system-wide phone numbers
- add that file to the search (grep) command
- write a method for adding new information to the system-wide file
- check that the data files exist, and create them if they don't
While I was at it, I changed grep to egrep to allow
multiple search criteria.
The scripts
ph
#!/bin/sh
# Mon Aug 28 12:52:49 EDT 2000
# ph - a simple phone book - version 0.2
# Copyright 2000, Chris F.A. Johnson
# released under the terms of the
# GNU General Public Licence
phbase="/info/data/phones $HOME/.phones"
for f in $phbase
do
if [ ! -f $f ]
then
touch $f
fi
done
egrep -ih "$@" $phbase
|
phadd
#!/bin/sh
# Mon Aug 28 13:08:54 EDT 2000
# phadd - script to add phone numbers to:
# ph - a simple phone book - version 0.2
# Copyright 2000, Chris F.A. Johnson
# released under the terms of the
# GNU General Public Licence
if [ "$1" = "-s" ]
then
phlist="/info/data/phones"
shift
else
phlist="$HOME/.phones"
fi
echo "$@" >> $phlist
|
phdel
#!/bin/sh
# Wed Feb 11 02:54:00 EST 2004
# NAME: phdel
# Copyright 2004, Chris F.A. Johnson
# Released under the terms of the
# GNU General Public License
if [ "$1" = "-s" ]
then
phlist=/info/data/phones
shift
else
phlist=$HOME/.phones
fi
grep -iv "$1" $phlist > /tmp/phdel$$
mv /tmp/phdel$$ $phlist
|
|
The future of ph
Over the years, I have had many ideas for improvements to
ph , from adding dialing, to making it into a full-fledged
address and phone book, and even adding a GUI interface. But I have
downloaded many address book programs over the years, and none of them
ever caught my fancy. So why would I want to make ph more like them?
In the end, I always decided to leave it alone. It is simple and it
is very quick, and it does what I need .
Conclusion
Writing this documentation and HTML page was much more work
than writing the scripts!
Recommended reading
Some of the philosophy behind ph can be found in the
Software Toolbox.
|