Last active
November 13, 2019 20:23
-
-
Save gpanders/e700b59c49d26528a93246a4c3c8facf to your computer and use it in GitHub Desktop.
Query lbdb and cache results into a mutt aliases file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Query lbdbq and save results to Mutt alias file | |
set -e | |
# Mutt aliases file to save results to | |
ALIASES="$HOME/.cache/mutt/aliases" | |
# Only save email addresses from $DOMAIN. Leave empty to save all email addresses | |
DOMAIN="example.com" | |
query_and_cache() { | |
results=$(lbdbq "$@" 2>/dev/null) | |
printf '%s\n' "$results" | |
# Remove first line from results | |
results=$(sed '1d' <<< "$results") | |
# Format results like mutt aliases | |
sed -E $'s/^([[:alnum:]_.]+)@([[:alnum:]_.]+)\t([[:alnum:] -]+)/alias \\1 \\1@\\2 (\\3)/' <<< "$results" | awk -v domain="$DOMAIN" '$3 ~ domain {$2=tolower($2);print}' >> "$ALIASES" | |
# Sort and remove duplicates | |
sort -u -o "$ALIASES" "$ALIASES" | |
} | |
query_and_cache "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment