elvish_config/aliases/digall.elv

70 lines
1.2 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 = []
fn init []{
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 digr [d @args]{
local:results = [ (each [r]{
e:dig $@args $r $d $@flags
} $records) ]
results = [ (list:remove-duplicate $results) ]
echo (str:join "\n" $results)
}
fn digs [s d]{
echo (styled $s bright-yellow)
digr $d $s
}
fn digd [d]{
echo (styled 'Domaine: '$d bright-green)
if (> (count $servers) 0) {
each [s]{
digs $s $d
} $servers
} else {
digr $d
}
}
init
each $digd~ $domains
}