Search contact with first arg and grep with second

This commit is contained in:
Jeremy Gardais 2020-08-19 16:07:59 +02:00
parent ca0b6cfa67
commit 93b0becacf
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 18 additions and 7 deletions

View File

@ -27,23 +27,34 @@ debug_message() {
# ]]] # ]]]
# Verify argument [[[ # Verify argument [[[
debug_message " Verify arguments: Script get ${#} argument(s)."
case "$#" in case "$#" in
0 ) 0 )
printf "${c_redb}%b${c_reset}\n" "Error: Expect at least one argument." printf "${c_redb}%b${c_reset}\n" "Error: Expect at least one argument."
exit 1 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." printf "${c_redb}%b${c_reset}\n" "Error: Expect between 1 and 2 arguments."
contact_pattern="${*}" exit 2
;; ;;
esac 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 if [ -n "${contact_line}" ]; then
debug_message "Matching contact:\n${contact_line}" debug_message "Matching contact:\n${contact_line}"