From 373316fddb70c436b6121c4d7957032316ff431f Mon Sep 17 00:00:00 2001 From: Gardouille Date: Wed, 18 Mar 2020 11:58:58 +0100 Subject: [PATCH] Init script to search contact's mail address --- kmail.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 kmail.sh diff --git a/kmail.sh b/kmail.sh new file mode 100755 index 0000000..4b8a56f --- /dev/null +++ b/kmail.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# .. vim: foldmarker=[[[,]]]:foldmethod=marker + +# This script will try to: +## Get arguments (at least one) +## Search contact that corresponding to arguments with khard +## Display _only_ the email address of the first match + +# Vars [[[ +debug=true + +## Colors [[[ +c_redb='\033[1;31m' +c_magentab='\033[1;35m' +c_reset='\033[0m' +## ]]] + +# ]]] + +# Functions +# Function to print a debug message [[[ +debug_message() { + _message="${1}" + + [ "${debug}" = "true" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG ${_message}" +} +# ]]] + +# Verify argument [[[ +case "$#" in + 0 ) + printf "${c_redb}%b${c_reset}\n" "Error : Expect at least one argument." + exit 1 + ;; + * ) + contact_pattern="$*" + ;; +esac +# ]]] + + +contact_line=$(khard email "${contact_pattern}" | sed -n 2p) + +contact_mail=$(printf '%s' "${contact_line}" | awk '{print $NF}') + +exit 0