From 556a4fd2dbce0aab2376374953d13ef86fbfa148 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Wed, 18 Mar 2020 15:40:17 +0100 Subject: [PATCH] Print message if no found contact --- kmail.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/kmail.sh b/kmail.sh index 50c4d20..122723e 100755 --- a/kmail.sh +++ b/kmail.sh @@ -39,14 +39,22 @@ case "$#" in esac # ]]] -debug_message "Look for a contact with these informations:\n${contact_pattern}" -contact_line=$(khard email "${contact_pattern}" | sed -n 2p) -debug_message "Matching contact:\n${contact_line}" +debug_message "− Look for a contact with these informations:\n${contact_pattern}" +{ + contact_line=$(khard email "${contact_pattern}" | sed -n 2p) +} > /dev/null -contact_mail=$(printf '%s' "${contact_line}" | awk '{print $NF}') -debug_message "Mail of this contact:\n${contact_mail}" +if [ -n "${contact_line}" ]; then + debug_message "Matching contact:\n${contact_line}" -# Print the message to X11 -printf '%s' "${contact_mail}" | xdotool type --clearmodifiers --file - + contact_mail=$(printf '%s' "${contact_line}" | awk '{print $NF}') + debug_message "Mail of this contact:\n${contact_mail}" +else + debug_message "− Found no email addresses corresponding to the argument(s)." + contact_mail="NO_CONTACT" +fi + + # Print the message to X11 + printf '%s' "${contact_mail}" | xdotool type --clearmodifiers --file - exit 0