elvish_config/aliases/digall.elv

91 lines
1.6 KiB
Plaintext

#alias:new digall e:dig ANY +noall +answer
fn digall [@_args]{
use moi/util/list
use str
local:default_records = [
A
AAAA
CNAME
PTR
TXT
MX
SRV
NAPTR
NS
SOA
]
local:records = []
local:servers = []
local:flags = [
+noall
+answer
]
local:domains = []
local:use_dig = $true
fn init []{
if (and (> (count $_args) 0) (is $_args[0] -d)) {
use_dig = $false
_args = $_args[1:]
}
each [e]{
if (is $e[0] '+') {
flags = [ (all $flags) $e ]
} elif (is $e[0] @) {
servers = [ (all $servers) $e ]
} elif (list:includes $e $default_records) {
records = [ (all $records) $e ]
} else {
domains = [ (all $domains) $e ]
}
} $_args
if (== (count $records) 0) {
records = $default_records
}
}
fn drillr [d @args]{
local:results = [ (peach [r]{
e:drill $@args $r $d | list:filter [e]{
and (> (count $e) 2) (not (is $e[:2] ';;'))
}
} $records | list:remove-duplicate) ]
echo (str:join "\n" $results)
}
fn digr [d @args]{
local:results = [ (peach [r]{
e:dig $@args $r $d $@flags
} $records | list:remove-duplicate) ]
echo (str:join "\n" $results)
}
fn req [d @args]{
if $use_dig {
digr $d $@args
} else {
drillr $d $@args
}
}
fn digs [s d]{
echo (styled $s bright-yellow)
req $d $s
}
fn digd [d]{
echo (styled 'Domaine: '$d bright-green)
if (> (count $servers) 0) {
each [s]{
digs $s $d
} $servers
} else {
req $d
}
}
init
each $digd~ $domains
}