scripts/kmail.sh

53 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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=false
## 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
;;
* )
debug_message " Verify arguments: Script get ${#} arguments."
contact_pattern="${*}"
;;
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}"
contact_mail=$(printf '%s' "${contact_line}" | awk '{print $NF}')
debug_message "Mail of this contact:\n${contact_mail}"
# Print the message to X11
printf '%s' "${contact_mail}" | xdotool type --clearmodifiers --file -
exit 0