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 0ccb3edfbd2a70d1ec282de5fcb6a44a484d68d8
parent 981abb2d7ff22103b721bdcacff96b0c532375c8
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Fri, 12 Jun 2020 19:22:36 -0400

Rename project to kontaktdb

Diffstat:
MMakefile | 2+-
MREADME.md | 10+++++-----
Dkontakt | 159-------------------------------------------------------------------------------
Akontaktdb | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 165 insertions(+), 165 deletions(-)

diff --git a/Makefile b/Makefile @@ -4,4 +4,4 @@ BINDIR?=$(_INSTDIR)/bin install: mkdir -m755 -p $(BINDIR) - install -m755 kontakt $(BINDIR)/kontakt + install -m755 kontaktdb $(BINDIR)/kontaktdb diff --git a/README.md b/README.md @@ -1,4 +1,4 @@ -# Kontakt +# Kontaktdb Store, retrieve, and edit basic contact information in plain text. @@ -28,7 +28,7 @@ distributions. ## Installing -`kontakt` is just a POSIX shell script. You can put it anywhere in your `$PATH` +`kontaktdb` 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 @@ -36,12 +36,12 @@ or type `make install` to have it automatically copied to `/usr/local/bin/`. 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 +If this variable is unset, kontaktdb 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 +If neither of the above environment variables are defined, kontaktdb will fall back to storing the database at `$HOME/.kontaktdb`. ## Using -See the output of `kontakt -h`. +See the output of `kontaktdb -h`. diff --git a/kontakt b/kontakt @@ -1,159 +0,0 @@ -#!/bin/sh - -# kontakt - Store, retrieve, and edit contact information in plain text -# -# Copyright (C) 2020 Jake Bauer -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -VERSION="0.1.0" - -# POSIX Shell "Strict Mode" -set -o errexit -set -o nounset -IFS=$(printf '\n\t') - -if [ -n "$KONTAKT_DB" ]; then - database="$KONTAKT_DB" -elif [ -n "$XDG_DATA_HOME" ]; then - database="$XDG_DATA_HOME"/kontaktdb -else - database="$HOME"/.kontaktdb -fi - -retrieve_contact() -{ - [ -z "$query" ] && echo "Please specify a query string" && exit 1 - grep -i "$query" "$database" || true -} - -add_contact() -{ - [ -z "$name" ] && echo "The contact's name must be specified" && exit 1 - [ -z "$email" ] && echo "The contact's email must be specified" && exit 1 - - exists=$(retrieve_contact) - if [ -n "$exists" ]; then - echo "A contact with that email already exists" - exit 1 - fi - - printf "%s\t%s\n" "$email" "$name" >> "$database" - echo "New contact added to database" -} - -delete_contact() -{ - original=$(retrieve_contact) - sed -i "/$original/d" "$database" - echo "Contact deleted from database" -} - -change_contact() -{ - [ -z "$name" ] && echo "The contact's new name must be specified" && exit 1 - [ -z "$email" ] && echo "The contact's new email must be specified" && exit 1 - - original=$(retrieve_contact) - sed -i "/$original/d" "$database" - - printf "%s\t%s\n" "$email" "$name" >> "$database" - echo "Contact information changed" -} - -helptext=$(cat << EOF -kontakt - Store, retrieve, and edit contact information in plain text - -Usage: kontakt {action} [arguments] - -Available actions: --h|--help show brief help and exit --v|--version print kontakt's version number and exit --a|--add <name> <email> add a contact to the database --c|--change <query> <name> <email> change an existing contact's information --r|--retrive <query> retrieve a contact's information --d|--delete <query> delete a contact --l|--list list all contacts in the database - -Friendly names of actions can also be used. E.g. 'kontakt add' is valid. - -Arguments: -<query> the string to search the database for -<name> the contact's name -<email> the contact's email - -Examples: - - $ kontakt -a "John Smith" "john.smith@example.com" - New contact added to database - - $ kontakt -r john - john.smith@example.com John Smith - - $ kontakt -c john "John Doe" "john.doe@example.com" - Contact information changed - - $ kontakt -d john - Contact deleted from database -EOF -) - -name="" -email="" -query="" - -while test $# -gt 0; do - case "$1" in - -h|--help|help) - echo "$helptext" - exit 0 - ;; - -v|--version|version) - echo "$VERSION" - exit 0 - ;; - -a|--add|add) - name=$2 - email=$3 - query=$email - add_contact - exit 0 - ;; - -c|--change|change) - query=$2 - name=$3 - email=$4 - change_contact - exit 0 - ;; - -r|--retrieve|retrieve) - query=$2 - retrieve_contact - exit 0 - ;; - -d|--delete|delete) - query=$2 - delete_contact - exit 0 - ;; - -l|--list|list) - cat "$database" - exit 0 - ;; - *) - echo "Unrecognized option; see 'kontakt help'." - exit 1 - ;; - esac -done diff --git a/kontaktdb b/kontaktdb @@ -0,0 +1,159 @@ +#!/bin/sh + +# kontaktdb - Store, retrieve, and edit contact information in plain text +# +# Copyright (C) 2020 Jake Bauer +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +VERSION="0.1.0" + +# POSIX Shell "Strict Mode" +set -o errexit +set -o nounset +IFS=$(printf '\n\t') + +if [ -n "$KONTAKT_DB" ]; then + database="$KONTAKT_DB" +elif [ -n "$XDG_DATA_HOME" ]; then + database="$XDG_DATA_HOME"/kontaktdb +else + database="$HOME"/.kontaktdb +fi + +retrieve_contact() +{ + [ -z "$query" ] && echo "Please specify a query string" && exit 1 + grep -i "$query" "$database" || true +} + +add_contact() +{ + [ -z "$name" ] && echo "The contact's name must be specified" && exit 1 + [ -z "$email" ] && echo "The contact's email must be specified" && exit 1 + + exists=$(retrieve_contact) + if [ -n "$exists" ]; then + echo "A contact with that email already exists" + exit 1 + fi + + printf "%s\t%s\n" "$email" "$name" >> "$database" + echo "New contact added to database" +} + +delete_contact() +{ + original=$(retrieve_contact) + sed -i "/$original/d" "$database" + echo "Contact deleted from database" +} + +change_contact() +{ + [ -z "$name" ] && echo "The contact's new name must be specified" && exit 1 + [ -z "$email" ] && echo "The contact's new email must be specified" && exit 1 + + original=$(retrieve_contact) + sed -i "/$original/d" "$database" + + printf "%s\t%s\n" "$email" "$name" >> "$database" + echo "Contact information changed" +} + +helptext=$(cat << EOF +kontaktdb - Store, retrieve, and edit contact information in plain text + +Usage: kontaktdb {action} [arguments] + +Available actions: +-h|--help show brief help and exit +-v|--version print kontaktdb's version number and exit +-a|--add <name> <email> add a contact to the database +-c|--change <query> <name> <email> change an existing contact's information +-r|--retrive <query> retrieve a contact's information +-d|--delete <query> delete a contact +-l|--list list all contacts in the database + +Friendly names of actions can also be used. E.g. 'kontaktdb add' is valid. + +Arguments: +<query> the string to search the database for +<name> the contact's name +<email> the contact's email + +Examples: + + $ kontaktdb -a "John Smith" "john.smith@example.com" + New contact added to database + + $ kontaktdb -r john + john.smith@example.com John Smith + + $ kontaktdb -c john "John Doe" "john.doe@example.com" + Contact information changed + + $ kontaktdb -d john + Contact deleted from database +EOF +) + +name="" +email="" +query="" + +while test $# -gt 0; do + case "$1" in + -h|--help|help) + echo "$helptext" + exit 0 + ;; + -v|--version|version) + echo "$VERSION" + exit 0 + ;; + -a|--add|add) + name=$2 + email=$3 + query=$email + add_contact + exit 0 + ;; + -c|--change|change) + query=$2 + name=$3 + email=$4 + change_contact + exit 0 + ;; + -r|--retrieve|retrieve) + query=$2 + retrieve_contact + exit 0 + ;; + -d|--delete|delete) + query=$2 + delete_contact + exit 0 + ;; + -l|--list|list) + cat "$database" + exit 0 + ;; + *) + echo "Unrecognized option; see 'kontaktdb help'." + exit 1 + ;; + esac +done