diff --git a/kmail.sh b/kmail.sh index 122723e..66334c6 100755 --- a/kmail.sh +++ b/kmail.sh @@ -27,23 +27,34 @@ debug_message() { # ]]] # Verify argument [[[ +debug_message "− Verify arguments : Script get ${#} argument(s)." case "$#" in 0 ) printf "${c_redb}%b${c_reset}\n" "Error : Expect at least one argument." exit 1 ;; + 1 ) + contact_info="${1}" + debug_message "− Look for a contact with these informations:\n${contact_info}" + { + contact_line=$(khard email "${contact_info}" | sed -n 2p) + } > /dev/null + ;; + 2 ) + contact_info="${1}" + filter_pattern="${2}" + debug_message "− Look for a contact with these informations:\n${contact_info}\nand filter results with:\n${filter_pattern}" + { + contact_line=$(khard email "${contact_info}" | grep -- "${filter_pattern}" | sed -n p) + } > /dev/null + ;; * ) - debug_message "− Verify arguments : Script get ${#} arguments." - contact_pattern="${*}" + printf "${c_redb}%b${c_reset}\n" "Error : Expect between 1 and 2 arguments." + exit 2 ;; esac # ]]] -debug_message "− Look for a contact with these informations:\n${contact_pattern}" -{ - contact_line=$(khard email "${contact_pattern}" | sed -n 2p) -} > /dev/null - if [ -n "${contact_line}" ]; then debug_message "Matching contact:\n${contact_line}"