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 0235b5ef49339a101d0407aee6b3d41b4cc5928c
parent 13077976f900f872841fd7d661232da4f298fa5d
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Sun, 14 Jun 2020 21:11:55 -0400

Fix retrieve not outputting to stdout

I did a dumb and forgot to print the retrieved contacts to stdout when
using the 'retrieve' command.

The way it works now is perhaps also a little bit easier to understand,
and doesn't cause an unnecessary call to escape_entry() to be made.

Diffstat:
Mkontaktdb | 23++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/kontaktdb b/kontaktdb @@ -19,10 +19,6 @@ VERSION="0.2.0" -# POSIX Shell "Strict Mode" (but unset variables are fine) -set -o errexit -IFS=$(printf '\n\t') - if [ -n "$KONTAKT_DB" ]; then database="$KONTAKT_DB" elif [ -n "$XDG_DATA_HOME" ]; then @@ -31,6 +27,11 @@ else database="$HOME"/.kontaktdb fi +# POSIX Shell "Strict Mode" +set -o errexit +set -o nounset +IFS=$(printf '\n\t') + touch $database queryfile="/tmp/kontaktdb-query-results.txt" @@ -76,8 +77,10 @@ EOF ) # Escapes all special BRE characters which could appear in a returned entry +# The first argument is the entry to escape escape_entry() { +echo "$1" > "$queryfile" entry=$(sed 's/\\/\\\\/g; s/\//\\\//g; s/\^/\\^/g; s/\[/\\[/g; s/\*/\\*/g; s/\./\\./g; s/\$/\\$/g' "$queryfile") } @@ -85,8 +88,7 @@ entry=$(sed 's/\\/\\\\/g; s/\//\\\//g; s/\^/\\^/g; s/\[/\\[/g; s/\*/\\*/g; retrieve_contact() { [ -z "$query" ] && echo "Please specify a query string" && exit 1 - grep -i "$query" "$database" > "$queryfile" || true - escape_entry + grep -i "$query" "$database" || true } add_contact() @@ -94,7 +96,8 @@ 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 - retrieve_contact + entry=$(retrieve_contact) + escape_entry "$entry" if [ -n "$entry" ]; then echo "A contact with that email already exists" exit 1 @@ -106,7 +109,8 @@ add_contact() delete_contact() { - retrieve_contact + entry=$(retrieve_contact) + escape_entry "$entry" sed -i "/$entry/d" "$database" echo "Contact deleted from database" } @@ -116,7 +120,8 @@ 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 - retrieve_contact + entry=$(retrieve_contact) + escape_entry "$entry" sed -i "/$entry/d" "$database" printf "%s\t%s\n" "$email" "$name" >> "$database"