kontaktdb

Store, retrieve, and edit basic contact information in plain text.
git clone https://git.sr.ht/~jbauer/kontaktdb
Log | Files | Refs | README | LICENSE

commit 981abb2d7ff22103b721bdcacff96b0c532375c8
parent 2f16f1684188939c949313567788cc00210b46f9
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Fri, 12 Jun 2020 18:07:29 -0400

Add KONTAKT_DB environment variable

It is used to manually specify the location for kontakt's database.

The database file is now also called "kontaktdb" because this name is
clearer than "addresses" and it matches the name of the environment
variable.

Diffstat:
MREADME.md | 11+++++++++++
Mkontakt | 20+++++++++++---------
2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md @@ -31,6 +31,17 @@ distributions. `kontakt` is just a POSIX shell script. You can put it anywhere in your `$PATH` or type `make install` to have it automatically copied to `/usr/local/bin/`. +## Configuring + +Set the `KONTAKT_DB` environment variable to specify the location of the contact +database file. + +If this variable is unset, kontakt will check if `XDG_DATA_HOME` is defined and +will put the database file there. + +If neither of the above environment variables are defined, kontakt will fall +back to storing the database at `$HOME/.kontaktdb`. + ## Using See the output of `kontakt -h`. diff --git a/kontakt b/kontakt @@ -24,16 +24,18 @@ set -o errexit set -o nounset IFS=$(printf '\n\t') -if [ -n "$XDG_DATA_HOME" ]; then - addressFile="$XDG_DATA_HOME"/addresses +if [ -n "$KONTAKT_DB" ]; then + database="$KONTAKT_DB" +elif [ -n "$XDG_DATA_HOME" ]; then + database="$XDG_DATA_HOME"/kontaktdb else - addressFile="$HOME"/.addresses + database="$HOME"/.kontaktdb fi retrieve_contact() { [ -z "$query" ] && echo "Please specify a query string" && exit 1 - grep -i "$query" "$addressFile" || true + grep -i "$query" "$database" || true } add_contact() @@ -47,14 +49,14 @@ add_contact() exit 1 fi - printf "%s\t%s\n" "$email" "$name" >> "$addressFile" + printf "%s\t%s\n" "$email" "$name" >> "$database" echo "New contact added to database" } delete_contact() { original=$(retrieve_contact) - sed -i "/$original/d" "$addressFile" + sed -i "/$original/d" "$database" echo "Contact deleted from database" } @@ -64,9 +66,9 @@ change_contact() [ -z "$email" ] && echo "The contact's new email must be specified" && exit 1 original=$(retrieve_contact) - sed -i "/$original/d" "$addressFile" + sed -i "/$original/d" "$database" - printf "%s\t%s\n" "$email" "$name" >> "$addressFile" + printf "%s\t%s\n" "$email" "$name" >> "$database" echo "Contact information changed" } @@ -146,7 +148,7 @@ while test $# -gt 0; do exit 0 ;; -l|--list|list) - cat "$addressFile" + cat "$database" exit 0 ;; *)