Dotfiles/bin/.bin/contact-numbers
Jonathan Hodgson 43f0dd09bc Many changes including introduction to menu system
THe main addition here is the menu system that is used to contoll the
phone. THere are also some small helper scripts for calls etc.
2021-04-04 16:04:22 +01:00

26 lines
740 B
Bash
Executable file

#!/usr/bin/env bash
addressbook="$HOME/.abook/addressbook"
filter(){
if [ -n "$1" ]; then
local str="$(echo "$1" | tr -d ' ' | sed 's/^0/+44/')"
grep -i "$str"
else
cat -
fi
}
cat "$addressbook" |
grep -E '(\[[0-9]+\]|^$|name|phone|mobile)' |
awk -v RS="\n\n" -v ORS="\n" '{gsub("\n","\t",$0); print $0}' |
grep -E "(phone|mobile)" | while read -r line; do
name="$(echo "$line" | cut -d ' ' -f 2 | cut -d '=' -f 2)"
echo "$line" | tr '\t' '\n' |
grep -E '(phone|mobile)' | while read -r numLine; do
num="$(echo "$numLine" | cut -d '=' -f 2 | tr -d ' ' |
sed 's/+44(0)/+44/' | sed 's/^0/+44/')"
numType="$(echo "$numLine" | cut -d '=' -f 1)"
echo -e "$name\t$num\t$numType"
done
done | filter "$*"