IngeniousSilliness

16th July 2017 at 1:24pm
Bash CodeSnippets
DOMAIN="${DOMAIN:-$(hostname -d)}"
USER="${USER:-$(id -un)}"
LOGNAME="$USER"
MYBLADE="blade-${USER}.${DOMAIN}"
 
alias blade='ssh ${MYBLADE}'
alias ll='ls -la'
 
zzz () {
    dig +short -t TXT "zzz.${MYBLADE}" | tr -d '"'
}
 
fqdn () {
    if [[ "${1}" =~ ^(cp|ac)[[:digit:]]+$ ]]; then
        echo "${1}.$(zzz)d1.cdn"
    elif [[ "${1}" =~ ^..[[:digit:]]+$ ]]; then
        echo "${1}.$(zzz)s1.cdn"
    else
        echo "${1}"
    fi
}
 
if [[ $(type -t command_not_found_handle_backup) != "function" ]]; then
    eval $(echo "command_not_found_handle_backup ()"; declare -f command_not_found_handle | tail -n +2)
fi
 
unset -f command_not_found_handle
 
command_not_found_handle () {
    if [[ "${1}" =~ ^(cp|ac)[[:digit:]]+$ ]]; then
        ssh $(fqdn "${1}")
    else
        command_not_found_handle_backup "${@}"
    fi
}